Skip to content

Commit

Permalink
- [#] update README
Browse files Browse the repository at this point in the history
  • Loading branch information
suntong committed Jul 17, 2021
1 parent 71375b6 commit c7a6ccd
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 10 deletions.
49 changes: 48 additions & 1 deletion README.e.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
SingleSel1: echo '<input type="radio" name="Sex" value="F" />' | tee /tmp/cascadia.xml | cascadia -i -o -c 'input[name=Sex][value=M]'
SingleSel1: echo '<input type="radio" name="Sex" value="F" />' | tee /tmp/cascadia.xml | cascadia -i -o -c 'input[name=Sex][value=F]'
SingleSel2: cascadia -i /tmp/cascadia.xml -o -c 'input[name=Sex][value=F]'
---

Expand Down Expand Up @@ -54,6 +54,53 @@ Either the input or the output can be followed by a file name:
$ {{shell .SingleSel2}}
```


```sh
$ cascadia -i /tmp/cascadia.xml -c 'input[name=Sex][value=F]' -o /tmp/out.html
1 elements for 'input[name=Sex][value=F]':

$ cat /tmp/out.html
<input type="radio" name="Sex" value="F"/>
```

More other options can be applied too:

```sh
# using --wrap-html
$ cascadia -i /tmp/cascadia.xml -c 'input[name=Sex][value=F]' -o /tmp/out.html -w
1 elements for 'input[name=Sex][value=F]':

$ cat /tmp/out.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base href="">

</head>
<body>
<input type="radio" name="Sex" value="F"/>
</body>

# using --wrap-html with --style
$ cascadia -i /tmp/cascadia.xml -c 'input[name=Sex][value=F]' -o /tmp/out.html -w -y '<link rel="stylesheet" href="styles.css">'
1 elements for 'input[name=Sex][value=F]':

$ cat /tmp/out.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base href="">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<input type="radio" name="Sex" value="F"/>
</body>
```

For more on using the `--style` option, check out ["adding styles"](https://github.com/suntong/cascadia/wiki/Adding-styles).

#### Multi-selection

Of course, any number of selections are allowed (provided out of box from the CSS selection "`,`" syntax):
Expand Down
57 changes: 53 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ The [Go Cascadia package](https://github.com/andybalholm/cascadia) implements CS
#### $ cascadia
```sh
cascadia wrapper
Version 1.2.3 built on 2020-04-20
Copyright (C) 2020, Tong Sun
Version 1.2.5 built on 2021-07-16
Copyright (C) 2021, Tong Sun

Command line interface to go cascadia CSS selectors package

Expand All @@ -52,6 +52,7 @@ Options:
RAW: will return the selected as-is; else the text will be returned
-d, --delimiter delimiter for pieces csv output [= ]
-w, --wrap-html wrap up the output with html tags
-y, --style style component within the wrapped html head
-b, --base base href tag used in the wrapped up html
-q, --quiet be quiet
```
Expand All @@ -78,8 +79,9 @@ This all sounds rather complicated, but in practice it's quite simple. See the n
All the three `-i -o -c` options are required. By default it reads from `stdin` and output to `stdout`:
```sh
$ echo '<input type="radio" name="Sex" value="F" />' | tee /tmp/cascadia.xml | cascadia -i -o -c 'input[name=Sex][value=M]'
0 elements for 'input[name=Sex][value=M]':
$ echo '<input type="radio" name="Sex" value="F" />' | tee /tmp/cascadia.xml | cascadia -i -o -c 'input[name=Sex][value=F]'
1 elements for 'input[name=Sex][value=F]':
<input type="radio" name="Sex" value="F"/>
```
Either the input or the output can be followed by a file name:
Expand All @@ -91,6 +93,53 @@ $ cascadia -i /tmp/cascadia.xml -o -c 'input[name=Sex][value=F]'
<input type="radio" name="Sex" value="F"/>
```
```sh
$ cascadia -i /tmp/cascadia.xml -c 'input[name=Sex][value=F]' -o /tmp/out.html
1 elements for 'input[name=Sex][value=F]':
$ cat /tmp/out.html
<input type="radio" name="Sex" value="F"/>
```
More other options can be applied too:
```sh
# using --wrap-html
$ cascadia -i /tmp/cascadia.xml -c 'input[name=Sex][value=F]' -o /tmp/out.html -w
1 elements for 'input[name=Sex][value=F]':
$ cat /tmp/out.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base href="">
</head>
<body>
<input type="radio" name="Sex" value="F"/>
</body>
# using --wrap-html with --style
$ cascadia -i /tmp/cascadia.xml -c 'input[name=Sex][value=F]' -o /tmp/out.html -w -y '<link rel="stylesheet" href="styles.css">'
1 elements for 'input[name=Sex][value=F]':
$ cat /tmp/out.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base href="">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<input type="radio" name="Sex" value="F"/>
</body>
```
For more on using the `--style` option, check out ["adding styles"](https://github.com/suntong/cascadia/wiki/Adding-styles).
#### Multi-selection
Of course, any number of selections are allowed (provided out of box from the CSS selection "`,`" syntax):
Expand Down
10 changes: 5 additions & 5 deletions cascadia_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func CascadiaC(ctx *cli.Context) error {
argv := ctx.Argv().(*rootT)
WrapHTMLBeg = fmt.Sprintf(`<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base href="%s">
%s
</head>
<head>
<meta charset="utf-8">
<base href="%s">
%s
</head>
<body>`, argv.Base, argv.Style)

Cascadia(argv.Filei, argv.Fileo, argv.CSS, argv.Piece, argv.Deli,
Expand Down

0 comments on commit c7a6ccd

Please sign in to comment.