File tree Expand file tree Collapse file tree 6 files changed +39
-26
lines changed Expand file tree Collapse file tree 6 files changed +39
-26
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+
3
+ const xml = require ( '..' ) ;
4
+
5
+ const [ name , fn ] = process . argv . slice ( 2 ) ;
6
+
7
+ const d = [ ] ;
8
+ process . stdin
9
+ . on ( 'data' , d . push . bind ( d ) )
10
+ . on ( 'end' , async ( ) => {
11
+ let data = await xml . read ( d . join ( '' ) ) ;
12
+ if ( name ) {
13
+ if ( name === '-e' && fn ) {
14
+ data = eval ( `(${ fn } )(data)` ) ;
15
+ } else {
16
+ data = data [ name ] ;
17
+ }
18
+ }
19
+ try {
20
+ console . log ( data ) ;
21
+ process . exit ( 0 ) ;
22
+ } catch ( e ) {
23
+ console . error ( e ) ;
24
+ process . exit ( - 1 ) ;
25
+ }
26
+ } )
Original file line number Diff line number Diff line change 1
- <import src =" item.wxml" />
2
- <view class =" question" >
3
- <view class =" question-title" >
4
- <text class =" question-id" >{{ question.I }}</text >
5
- <text >{{ question.Q }}</text >
6
- </view >
7
- <view wx : if =" {{ question.P }}" >
8
- <image class =" question-image" mode =" aspectFit" src =" https://lsong.org/~lsong/HAM/img/{{question.P}}" />
9
- </view >
10
- <view class =" question-options" >
11
- <view bindtap =" onTapOption" wx : for =" {{ question.options }}" wx : for-item =" option" wx : key =" {{ question.I }}" data-option =" {{ option }}" class =" question-option question-option-{{index}} question-option-{{ option.style }}" >
12
- {{ option.text }}
13
- </view >
14
- </view >
15
- </view >
Original file line number Diff line number Diff line change @@ -6,10 +6,5 @@ const printer = require('../printer');
6
6
const traverse = require ( '../traverse' ) ;
7
7
8
8
xml . readFile ( __dirname + '/demo.xml' ) . then ( obj => {
9
- traverse ( obj , node => {
10
- if ( node . name === 'image' ) {
11
- node . attributes . src = 'abc' ;
12
- }
13
- } ) ;
14
- console . log ( xml . serialize ( obj ) ) ;
9
+ console . log ( obj ) ;
15
10
} ) ;
Original file line number Diff line number Diff line change @@ -8,13 +8,13 @@ const EventEmitter = require('events');
8
8
9
9
class XML extends EventEmitter {
10
10
static read ( str ) {
11
- return new Promise ( done => reader ( done ) ( str ) ) ;
11
+ return new Promise ( done => reader ( done ) ( `<root>${ str } </root>` ) )
12
+ . then ( root => root . children ) ;
12
13
}
13
14
static async readFile ( filename , options = { } ) {
14
15
const readFile = promisify ( fs . readFile ) ;
15
16
const source = await readFile ( filename , 'utf8' ) ;
16
- const ast = await XML . read ( `<root>${ source } </root>` , options ) ;
17
- return ast . children ;
17
+ return XML . read ( source , options ) ;
18
18
}
19
19
static serialize ( ast , options ) {
20
20
return printer ( ast , options ) ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " xml2" ,
3
- "version" : " 0.0.10 " ,
3
+ "version" : " 0.0.11 " ,
4
4
"description" : " simple xml reader and parser" ,
5
5
"main" : " index.js" ,
6
6
"browser" : " browser.js" ,
7
7
"scripts" : {
8
8
"build" : " rollup -c"
9
9
},
10
+ "bin" : " ./bin/xml2" ,
10
11
"repository" : {
11
12
"type" : " git" ,
12
13
"url" : " git+https://github.com/song940/xmljs.git"
Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ const ACTIONS = {
20
20
quote : 'action-quote' ,
21
21
slash : 'action-slash' ,
22
22
char : 'action-char' ,
23
- bang : 'action-bang'
23
+ bang : 'action-bang' ,
24
+ question : 'action-question'
24
25
} ;
25
26
26
27
const TYPES = {
@@ -44,6 +45,7 @@ const charToAction = {
44
45
'=' : ACTIONS . equal ,
45
46
'/' : ACTIONS . slash ,
46
47
'!' : ACTIONS . bang ,
48
+ '?' : ACTIONS . question ,
47
49
} ;
48
50
49
51
const noop = ( ) => { } ;
@@ -155,6 +157,10 @@ module.exports = emit => {
155
157
state = STATES . DATA ;
156
158
} ,
157
159
[ ACTIONS . space ] : noop ,
160
+ [ ACTIONS . question ] : ( ) => {
161
+ isClosing = true ;
162
+ state = STATES . TAG_END ;
163
+ } ,
158
164
[ ACTIONS . slash ] : ( ) => {
159
165
isClosing = true ;
160
166
state = STATES . TAG_END ;
You can’t perform that action at this time.
0 commit comments