@@ -15,7 +15,7 @@ import rehypeStringify from 'rehype-stringify';
1515import remarkRuby from ' remark-ruby' ;
1616
1717const config = {
18- title: ' Markdown processor customization example' ,
18+ title: ' Processor customization example' ,
1919 entry: [' manuscript.md' ],
2020 // config is StringifyMarkdownOptions in @vivliostyle/vfm
2121 // metadata is Metadata in @vivliostyle/vfm
@@ -41,12 +41,12 @@ export default config;
4141You can also set ` documentProcessor ` and ` documentMetadataReader ` for individual entries. This allows different processing for each file:
4242
4343``` js
44- import { defineConfig , VFM , readMetadata } from ' @vivliostyle/cli' ;
44+ import { defineConfig , VFM } from ' @vivliostyle/cli' ;
4545import unified from ' unified' ;
4646// ... other imports
4747
4848const config = defineConfig ({
49- title: ' Markdown processor customization example' ,
49+ title: ' Processor customization example' ,
5050 entry: [
5151 // Uses the global documentProcessor
5252 ' manuscript.md' ,
@@ -55,8 +55,7 @@ const config = defineConfig({
5555 path: ' manuscript2.md' ,
5656 documentProcessor: VFM ,
5757 documentMetadataReader : (content ) => {
58- const match = content .match (/ ^ #\s + (. + )$ / m );
59- return { title: match ? match[1 ] : ' Untitled' };
58+ return { title: ' Custom title' };
6059 },
6160 },
6261 ],
@@ -75,3 +74,44 @@ const config = defineConfig({
7574
7675export default config ;
7776```
77+
78+ ## htmlProcessor and xhtmlProcessor
79+
80+ While ` documentProcessor ` handles Markdown-to-HTML conversion, ` htmlProcessor ` and ` xhtmlProcessor ` allow you to customize the processing of HTML and XHTML source files respectively.
81+
82+ You can extend the built-in ` defaultHtmlProcessor ` (or ` defaultXhtmlProcessor ` for XHTML) with additional [ rehype] ( https://github.com/rehypejs/rehype ) plugins:
83+
84+ ``` js
85+ import { defineConfig , defaultHtmlProcessor } from ' @vivliostyle/cli' ;
86+ import { visit } from ' unist-util-visit' ;
87+
88+ const openLinksInNewTab = () => (tree ) => {
89+ visit (tree, ' element' , (node ) => {
90+ if (
91+ node .tagName === ' a' &&
92+ String (node .properties ? .href ).startsWith (' http' )
93+ ) {
94+ (node .properties ?? = {}).target = ' _blank' ;
95+ node .properties .rel = ' noopener noreferrer' ;
96+ node .children .push ({
97+ type: ' element' ,
98+ tagName: ' span' ,
99+ properties: {},
100+ children: [{ type: ' text' , value: ' ↗' }],
101+ });
102+ }
103+ });
104+ };
105+
106+ const config = defineConfig ({
107+ entry: [
108+ {
109+ path: ' page.html' ,
110+ htmlProcessor : (options ) =>
111+ defaultHtmlProcessor (options).use (openLinksInNewTab),
112+ },
113+ ],
114+ });
115+
116+ export default config ;
117+ ` ` `
0 commit comments