Additional Notes:
84 |-
86 |
├── .eslintrc.json
├── .gitattributes
├── .github
└── workflows
│ └── node.yml
├── .gitignore
├── .mailmap
├── .npmignore
├── CONTRIBUTING.md
├── Gruntfile.js
├── LICENSE.txt
├── README.md
├── entries2html.xsl
├── fixture
├── entries
│ └── addClass.xml
├── pages
│ ├── Hello_World.html
│ └── Mark.md
└── resources
│ └── x.txt
├── index.js
├── lib
├── highlight.js
├── lineNumberTemplate.jst
└── util.js
├── package-lock.json
├── package.json
├── tasks
├── build-xml.js
├── build.js
├── jquery-xml
│ ├── all-entries.xml
│ ├── all-entries.xsl
│ ├── cat2tax.xsl
│ ├── entries2html-base.xsl
│ └── xml2json.xsl
├── redirects.js
└── wordpress.js
└── test
├── build.test.js
├── expected
└── wordpress
│ ├── posts
│ ├── page
│ │ └── pages
│ │ │ ├── Hello_World.html
│ │ │ └── Mark.html
│ └── post
│ │ └── addClass.html
│ └── resources
│ └── resources
│ └── x.txt
└── lint.test.js
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 |
4 | "extends": "jquery",
5 |
6 | "reportUnusedDisableDirectives": true,
7 |
8 | "env": {
9 | "es2023": true,
10 | "node": true
11 | },
12 |
13 | "rules": {
14 | "strict": [ "error", "global" ]
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # JS files must always use LF for tools to work
5 | *.js eol=lf
6 |
--------------------------------------------------------------------------------
/.github/workflows/node.yml:
--------------------------------------------------------------------------------
1 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
2 |
3 | name: Node.js
4 |
5 | on:
6 | - push
7 | - pull_request
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 |
14 | strategy:
15 | matrix:
16 | node-version: [18.x, 20.x]
17 |
18 | steps:
19 | - name: Install Debian packages
20 | run: sudo apt-get install -y libxml2-utils xsltproc
21 | - uses: actions/checkout@v3
22 | - name: Install Node.js ${{ matrix.node-version }}
23 | uses: actions/setup-node@v3
24 | with:
25 | node-version: ${{ matrix.node-version }}
26 | cache: 'npm'
27 | - run: npm ci
28 | - run: npm test
29 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules
2 | /test/dist
3 |
--------------------------------------------------------------------------------
/.mailmap:
--------------------------------------------------------------------------------
1 | Michał Gołębiowski-Owczarek This method does not replace a class. It simply adds the class. The
203 | ```
204 |
205 | Where `resources/code-sample.html` is a relative path in the current directory. That html file will be inserted, escaped and highlighted.
206 |
207 | ### `@placeholder`
208 |
209 | Inside markup included with `@partial`, you can mark sections of code as `@placeholder` code, to be excluded from the inserted code, replaced with an html comment.
210 |
211 | Usage:
212 |
213 | ```html
214 | regular markup will show up here
215 |
216 | this will be replaced
217 |
218 | other content
219 | ```
220 |
221 | That will result in:
222 |
223 | ```html
224 | regular markup will show up here
225 |
226 | other content
227 | ```
228 |
229 | ## Exports
230 |
231 | The grunt-jquery-content module primarily registers Grunt tasks, but it also exports some methods through the `require()` API.
232 |
233 | ### `syntaxHighlight( content )`
234 |
235 | Syntax highlights content.
236 |
237 | * `content` String: The string the highlight.
238 |
239 | ### `postPreprocessors`
240 |
241 | Hooks for modifying the posts before they're processed in the [`build-posts`](#build-posts) task.
242 |
243 | `postPreprocessors` is a hash of preprocessors, where the key is the post type and the value is a function which modifies the post.
244 |
245 | The functions must be in the form of:
246 | `function( post, fileName, callback )`
247 |
248 | * `post` Object: The post being processed.
249 | * `fileName` String: The name of the file used to generate the post object.
250 | * `callback` function( error, post ): Callback to invoke after modifying the post.
251 | * `error`: An `Error` instance, if there was an error while modifying the post.
252 | * `post` The modified post.
253 |
254 | By default, posts are placed in the `[wordpress.dir]/[post-type]` directory using the same relative path and file name as the source file. The relative path can be changed by setting the `fileName` property on the post.
255 |
256 | If a preprocessor is not defined for the given post type, then the `_default` preprocessor will be used.
257 |
--------------------------------------------------------------------------------
/entries2html.xsl:
--------------------------------------------------------------------------------
1 | @partial(resources/code-sample.html)
25 |
23 | $( "p" ).addClass( "myClass yourClass" );
24 |
.addClass()
method changes the className
property on the selected elements.
and
44 |Goodbye
45 | ]]> 46 | 47 |Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pellentesque placerat arcu, vel viverra augue posuere commodo. Aenean hendrerit quam sed commodo pellentesque.
7 |Donec sed commodo velit, non molestie justo.
8 |Cras vel justo molestie lorem auctor convallis. Donec ac lacus tincidunt, euismod lectus eu, pulvinar tortor.
10 | Hello.world({
11 | // Handle the event
12 | // ......
13 | });
14 |
15 | Aliquam venenatis sem elit, et aliquet libero ultrices vitae. Nullam rutrum convallis justo, sed suscipit leo facilisis et. 17 |
18 | -------------------------------------------------------------------------------- /fixture/pages/Mark.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | **Conubia linguae** hydrae novissima recepto certe, clarus quod amictus tum ignota fluctibus *et quod*, est verba capitum, variusque. Sui saevam gentes propiora Cycladas, Hecate stamina nurus ramum! 6 | 7 | ## Oculi miserarum 8 | 9 | Lorem [markdownum](https://en.wikipedia.org/wiki/Markdown) silentia umerique, colla. Per felix innoxia pariterque capillos accessit, nec ad tempore in nubes detrahitur. 10 | 11 | Aures precantibus supplice Medusaeo, Lycormas est esse aestuat aut Pterelas. 12 | 13 | ## Domitos interea 14 | 15 | 1. Non torsi numine amor 16 | 2. Tamen vino hinc indignatus aquas iunguntur sacrifica 17 | 3. Solitum bacae tellure ille 18 | -------------------------------------------------------------------------------- /fixture/resources/x.txt: -------------------------------------------------------------------------------- 1 | x 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const syntaxHighlight = require( "./lib/highlight" ); 4 | 5 | exports.syntaxHighlight = syntaxHighlight; 6 | 7 | exports.postPreprocessors = { 8 | _default( post, _fileName, callback ) { 9 | callback( null, post ); 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /lib/highlight.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const fs = require( "fs" ); 4 | const hljs = require( "highlight.js" ); 5 | const cheerio = require( "cheerio" ); 6 | const he = require( "he" ); 7 | const grunt = require( "grunt" ); 8 | const lineNumberTemplate = fs.readFileSync( __dirname + "/lineNumberTemplate.jst", "utf-8" ); 9 | 10 | // When parsing the class attribute, make sure a class matches an actually 11 | // highlightable language, instead of being presentational (e.g. 'example') 12 | function getLanguageFromClass( str ) { 13 | var classes = ( str || "" ).split( " " ), 14 | i = 0, 15 | length = classes.length; 16 | 17 | for ( ; i < length; i++ ) { 18 | if ( hljs.getLanguage( classes[ i ].replace( /^lang-/, "" ) ) ) { 19 | return classes[ i ].replace( /^lang-/, "" ); 20 | } 21 | } 22 | 23 | return ""; 24 | } 25 | 26 | function outdent( string ) { 27 | var rOutdent, 28 | adjustedLines = [], 29 | minTabs = Infinity, 30 | rLeadingTabs = /^\t+/; 31 | 32 | string.split( "\n" ).forEach( function( line, i, arr ) { 33 | 34 | // Don't include first or last line if it's nothing but whitespace 35 | if ( ( i === 0 || i === arr.length - 1 ) && !line.trim().length ) { 36 | return; 37 | } 38 | 39 | // For empty lines inside the snippet, push a space so the line renders properly 40 | if ( !line.trim().length ) { 41 | adjustedLines.push( " " ); 42 | return; 43 | } 44 | 45 | // Count how many leading tabs there are and update the global minimum 46 | var match = line.match( rLeadingTabs ), 47 | tabs = match ? match[ 0 ].length : 0; 48 | minTabs = Math.min( minTabs, tabs ); 49 | 50 | adjustedLines.push( line ); 51 | } ); 52 | 53 | if ( minTabs !== Infinity ) { 54 | 55 | // Outdent the lines as much as possible 56 | rOutdent = new RegExp( "^\t{" + minTabs + "}" ); 57 | adjustedLines = adjustedLines.map( function( line ) { 58 | return line.replace( rOutdent, "" ); 59 | } ); 60 | } 61 | 62 | return adjustedLines.join( "\n" ); 63 | } 64 | 65 | function syntaxHighlight( html ) { 66 | 67 | // The third parameter is `false` to disable wrapping contents 68 | // in `...`, etc. 69 | var $ = cheerio.load( html, null, false ); 70 | 71 | $( "pre > code" ).each( function() { 72 | var $t = $( this ), 73 | code = he.decode( outdent( $t.html() ) ), 74 | lang = $t.attr( "data-lang" ) || 75 | getLanguageFromClass( $t.attr( "class" ) ) || 76 | ( code.trim().charAt( 0 ) === "<" ? "xml" : "" ) || 77 | "javascript", 78 | linenumAttr = $t.attr( "data-linenum" ), 79 | linenum = parseInt( linenumAttr, 10 ) || 1, 80 | gutter = linenumAttr !== "false", 81 | highlighted = hljs.highlight( code, { language: lang } ), 82 | fixed = highlighted.value.replace( /\t/g, " " ); 83 | 84 | // Handle multi-line comments (#32) 85 | fixed = fixed.replace( 86 | /\/\*([^<]+)\*\/<\/span>/g, 87 | function( _full, comment ) { 88 | return "/*" + 89 | comment.split( "\n" ).join( "\n" ) + 90 | "*/"; 91 | } 92 | ); 93 | 94 | $t.parent().replaceWith( grunt.template.process( lineNumberTemplate, { 95 | data: { 96 | lines: fixed.split( "\n" ), 97 | startAt: linenum, 98 | gutter: gutter, 99 | lang: lang 100 | } 101 | } ) ); 102 | } ); 103 | 104 | return $.html(); 105 | } 106 | 107 | module.exports = syntaxHighlight; 108 | -------------------------------------------------------------------------------- /lib/lineNumberTemplate.jst: -------------------------------------------------------------------------------- 1 |
7 | <% _.forEach(lines, function(line, i) { %>
8 | <%= i + startAt %>
9 | <% }); %>
10 | |
11 | <% } %>
12 |
13 | <% _.forEach(lines, function(line, i) { %>14 | |
15 |
Description:
263 |
Additional properties on the event object:
315 |
422 |
425 |
487 | The
Initialize the
option specified:
599 | $( ".selector" ).
600 |
601 | ({
602 |
603 | :
604 |
605 |
});
606 |
607 |
608 |
609 |
619 |
622 | // Getter
623 | var
624 |
625 | = $( ".selector" ).
626 |
627 | ( "option", "
628 |
629 | " );
630 |
631 |
632 |
633 | // Setter
634 | $( ".selector" ).
635 |
636 | ( "option", "
637 |
638 | ",
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 | );
651 |
652 |
653 |
678 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
705 |
706 |
707 |
)Invoke the
1036 |
1037 | var
1038 |
1039 | =
1040 |
1041 | $( ".selector" ).
1042 |
1043 | ( "
1044 |
1045 | "
1046 |
1047 | ,
1048 |
1049 |
1050 | );
1051 |
1052 |
1057 |
1058 |
1059 |
1122 | Note: The ui
object is empty but included for consistency with other events.
Initialize the
1141 | $( ".selector" ).
1142 |
1143 | ({
1144 |
1145 | : function( event, ui ) {}
});
1146 |
1147 |
1148 | Bind an event listener to the
1150 | $( ".selector" ).on( " ", function( event, ui ) {} );
1151 |
1152 |
1153 |
1157 |
1158 |
1159 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pellentesque placerat arcu, vel viverra augue posuere commodo. Aenean hendrerit quam sed commodo pellentesque.
4 |Donec sed commodo velit, non molestie justo.
5 |Cras vel justo molestie lorem auctor convallis. Donec ac lacus tincidunt, euismod lectus eu, pulvinar tortor.
7 |
13 |
14 | 1
15 |
16 | 2
17 |
18 | 3
19 |
20 | 4
21 |
22 | |
23 |
24 |
25 |
26 | |
27 |
Aliquam venenatis sem elit, et aliquet libero ultrices vitae. Nullam rutrum convallis justo, sed suscipit leo facilisis et. 34 |
35 | -------------------------------------------------------------------------------- /test/expected/wordpress/posts/page/pages/Mark.html: -------------------------------------------------------------------------------- 1 | 2 |Conubia linguae hydrae novissima recepto certe, clarus quod amictus tum ignota fluctibus et quod, est verba capitum, variusque. Sui saevam gentes propiora Cycladas, Hecate stamina nurus ramum!
3 |Lorem markdownum silentia umerique, colla. Per felix innoxia pariterque capillos accessit, nec ad tempore in nubes detrahitur.
4 |Aures precantibus supplice Medusaeo, Lycormas est esse aestuat aut Pterelas.
5 |Description: Adds the specified class(es) to each element in the set of matched elements.
16 |This method does not replace a class. It simply adds the class.
44 |
50 |
51 | 1
52 |
53 | |
54 |
55 |
56 |
57 | |
58 |
The .addClass()
method changes the className
property on the selected elements.
Add the class "selected" to the matched elements.
67 |
73 |
74 | 1
75 |
76 | 2
77 |
78 | 3
79 |
80 | 4
81 |
82 | 5
83 |
84 | 6
85 |
86 | 7
87 |
88 | 8
89 |
90 | 9
91 |
92 | 10
93 |
94 | 11
95 |
96 | 12
97 |
98 | 13
99 |
100 | 14
101 |
102 | 15
103 |
104 | 16
105 |
106 | |
107 |
108 |
109 |
110 | |
111 |