├── .editorconfig ├── .gitignore ├── .npmignore ├── .travis.yml ├── Gruntfile.js ├── LICENSE ├── README.md ├── example ├── .gitignore ├── DefaultIcon.png ├── Resources │ └── app.js ├── app │ ├── config.json │ ├── controllers │ │ └── index.js │ ├── lib │ │ └── xp.ui.js │ ├── styles │ │ └── app.tss │ ├── views │ │ └── index.xml │ └── widgets │ │ └── nl.fokkezb.html2as.widget │ │ ├── README.md │ │ ├── controllers │ │ └── widget.js │ │ ├── views │ │ └── widget.xml │ │ └── widget.json ├── plugins │ └── ti.alloy │ │ ├── hooks │ │ ├── alloy.js │ │ └── deepclean.js │ │ └── plugin.py └── tiapp.xml ├── index.js ├── package.json ├── screencast.gif ├── spec └── support │ └── jasmine.json └── test ├── specs └── indexSpec.js └── spies └── TiSpy.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /coverage 2 | /node_modules 3 | /spec 4 | /test 5 | .DS_Store 6 | /*.zip 7 | /npm-debug.log 8 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /.git 2 | /coverage 3 | /example 4 | /node_modules 5 | /spec 6 | /test 7 | .DS_Store 8 | /.editorconfig 9 | /.gitignore 10 | /.travis.yml 11 | /*.zip 12 | /npm-debug.log 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | env: 3 | - NODE_VERSION="0.10" 4 | - NODE_VERSION="0.12" 5 | # Disabling versions that fail because of https://github.com/smclab/grunt-titaniumifier/issues/3 6 | # - NODE_VERSION="4.4" 7 | # - NODE_VERSION="5.9" 8 | os: 9 | - osx 10 | matrix: 11 | fast_finish: true 12 | before_install: 13 | - git clone https://github.com/creationix/nvm.git /tmp/.nvm; 14 | - source /tmp/.nvm/nvm.sh; 15 | - nvm install $NODE_VERSION; 16 | - nvm use --delete-prefix $NODE_VERSION; 17 | install: 18 | - npm install 19 | script: 20 | - npm test 21 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(grunt) { 4 | 5 | grunt.initConfig({ 6 | 7 | pkg: grunt.file.readJSON('package.json'), 8 | 9 | clean: { 10 | unzip: ['modules'], 11 | modules: ['example/modules'], 12 | app: ['example/build'] 13 | }, 14 | 15 | titaniumifier: { 16 | module: { 17 | src: '.', 18 | dest: '.' 19 | } 20 | }, 21 | 22 | titanium: { 23 | ios: { 24 | options: { 25 | command: 'build', 26 | logLevel: 'debug', 27 | projectDir: './example', 28 | platform: 'ios' 29 | } 30 | } 31 | }, 32 | 33 | unzip: { 34 | module: { 35 | src: 'nl.fokkezb.html2as-commonjs-<%= pkg.version %>.zip', 36 | dest: 'example' 37 | } 38 | } 39 | 40 | }); 41 | 42 | grunt.loadNpmTasks('grunt-contrib-clean'); 43 | grunt.loadNpmTasks('grunt-titaniumifier'); 44 | grunt.loadNpmTasks('grunt-titanium'); 45 | grunt.loadNpmTasks('grunt-zip'); 46 | 47 | grunt.registerTask('build', ['titaniumifier:module']); 48 | grunt.registerTask('update', ['unzip:module']); 49 | grunt.registerTask('test', ['update', 'titanium:ios', 'clean:unzip']); 50 | 51 | grunt.registerTask('ios', ['clean', 'build', 'test']); 52 | 53 | grunt.registerTask('default', ['ios']); 54 | }; 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2015 Fokke Zandbergen 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HTML to Attributed String 2 | 3 | [![Dependencies](https://david-dm.org/fokkezb/ti-html2as/status.svg?style=flat-square)](https://david-dm.org/fokkezb/ti-html2as#info=dependencies) 4 | [![Dev Dependencies](https://david-dm.org/fokkezb/ti-html2as/dev-status.svg?style=flat-square)](https://david-dm.org/fokkezb/ti-html2as#info=devDependencies) [![Build Status](https://travis-ci.org/FokkeZB/ti-html2as.svg?branch=master)](https://travis-ci.org/FokkeZB/ti-html2as) 5 | 6 | HTML to [Ti.UI.AttributedString](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.AttributedString) parser for [Titanium](http://appcelerator.com/titanium). 7 | 8 | ## Screencast 9 | 10 | ![screencast](screencast.gif) 11 | 12 | ## Usage 13 | A packaged *CommonJS* module can be found via [Releases](https://github.com/fokkezb/ti-html2as/releases). Follow the guide on [Using a Module](http://docs.appcelerator.com/titanium/latest/#!/guide/Using_a_Module) or use gitTio: 14 | 15 | gittio install nl.fokkezb.html2as 16 | 17 | The module exports a single function that takes an HTML string and a callback to receive an error or [Ti.UI.AttributedString](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.AttributedString) object. 18 | 19 | ``` 20 | var html2as = require('nl.fokkezb.html2as'); 21 | 22 | html2as( 23 | 'Hello Bold World', 24 | function(err, as) { 25 | 26 | if (err) { 27 | console.error(err); 28 | 29 | } else { 30 | 31 | var label = Titanium.UI.createLabel({ 32 | attributedString: as 33 | }); 34 | 35 | label.addEventListener('link', function(e) { 36 | alert('Longtap on link to: ' + e.url); 37 | }); 38 | 39 | view.add(label); 40 | } 41 | } 42 | ); 43 | ``` 44 | 45 | ### Alloy 46 | 47 | In Alloy you can use the [XP.UI](https://github.com/FokkeZB/UTiL/blob/master/docs/xp.ui.md#tag-label) CommonJS module to emulate the `html` attribute Android has for `