@@ -10,10 +10,7 @@ const fs = require('node:fs')
1010const path = require ( 'node:path' )
1111
1212const pluginImages = require ( './eleventy.config.images.js' )
13-
14- function escapeHTML ( string ) {
15- return string . replace ( / < / g, '<' ) . replace ( / > / g, '>' )
16- }
13+ const tracToHTML = require ( './eleventy.config.tracToHTML.js' )
1714
1815module . exports = function ( eleventyConfig ) {
1916 // Copy the contents of the `public` folder to the output folder
@@ -159,147 +156,7 @@ module.exports = function (eleventyConfig) {
159156 )
160157 } )
161158
162- // Customize Markdown library settings:
163- // eleventyConfig.amendLibrary('md', (mdLib) => {
164- // mdLib.use(markdownItAnchor, {
165- // permalink: markdownItAnchor.permalink.ariaHidden({
166- // placement: 'after',
167- // class: 'header-anchor',
168- // symbol: '#',
169- // ariaHidden: false
170- // }),
171- // level: [1, 2, 3, 4],
172- // slugify: eleventyConfig.getFilter('slugify')
173- // })
174- // })
175-
176- const rasterisks = / ^ \s * \* /
177- const rheaders = / ^ * ( \= + ) * ( [ ^ \n \r ] + ) * \1? * $ /
178- let listStarted = false
179- eleventyConfig . addFilter ( 'tracToHTML' , ( text ) => {
180- const codes = [ ]
181- const pres = [ ]
182- return (
183- escapeHTML ( text )
184- // Newlines have extra escapes in the strings
185- . replace ( / \\ \n / g, '\n' )
186- // Replace `` with <code> tags
187- . replace ( / ` ( [ ^ \r \n ` ] + ?) ` / g, ( _match , code ) => {
188- codes . push ( code ) // Save the code for later
189- return `<code></code>`
190- } )
191- // Replace {{{ }}} with <pre> tags
192- . replace ( / { { { ( [ ^ ] + ?) } } } / g, ( _match , code ) => {
193- // Save the code for later
194- pres . push (
195- // Remove language hints
196- code . replace ( / ^ # ! \w + \r ? \n / , '' )
197- )
198- return `<pre class="wiki"></pre>`
199- } )
200- // Linkify http links in brackets
201- . replace (
202- / \[ ( h t t p s ? : \/ \/ [ ^ \s \] ] + ) (?: \s + ( [ ^ \] ] + ) ) ? \] / g,
203- function ( _match , url , text ) {
204- return `<a href="${ url } " class="ext-link"><span class="icon"></span>${
205- text || url
206- } </a>`
207- }
208- )
209- // Linkify hash links in brackets
210- . replace (
211- / \[ ( # [ ^ \s \] ] + ) (?: \s + ( [ ^ \] ] + ) ) ? \] / g,
212- function ( _match , url , text ) {
213- return `<a href="${ url } " class="ext-link"><span class="icon"></span>${
214- text || url
215- } </a>`
216- }
217- )
218- // Linkify CamelCase links in brackets
219- . replace (
220- / \[ ( [ A - Z ] [ a - z ] + [ A - Z ] [ \w # - ] + ) (?: \s + ( [ ^ \] ] + ) ) ? \] / g,
221- function ( _match , page , text ) {
222- return `<a href="/wiki/${ page } ">${ text || page } </a>`
223- }
224- )
225- // Linkify trac links
226- . replace (
227- / (?: \[ t r a c : ( [ ^ ] + ) " ( [ ^ " ] + ) " \] ) | (?: \[ t r a c : ( [ ^ \s \] ] + ) (?: ( [ ^ \] ] + ) ) ? \] ) / g,
228- function ( _match , quotepage , quotedtext , page , text ) {
229- return `<a href="https://trac.edgewall.org/intertrac/${
230- quotepage || page
231- } " class="ext-link"><span class="icon"></span>${
232- quotedtext || text || page
233- } </a>`
234- }
235- )
236- // Linkify ticket references (avoid trac ticket links)
237- . replace ( / # ( \d + ) (? ! < = > ) / g, `<a href="/ticket/$1">$&</a>` )
238- // Linkify CamelCase to wiki
239- . replace (
240- / ( ^ | \s ) ( ! ) ? ( [ A - Z ] [ a - z ] + [ A - Z ] \w + (?: # \w + ) ? ) (? ! \w ) / g,
241- function ( _match , space , excl , page ) {
242- if ( excl ) {
243- return `${ space } ${ page } `
244- }
245- return `${ space } <a href="/wiki/${ page } ">${ page } </a>`
246- }
247- )
248- // Convert ---- to <hr>
249- . replace ( / ^ - - + $ / gm, '<hr />' )
250- // Replace three single quotes with <strong>
251- . replace ( / ' ' ' ( [ ^ ' ] + ) ' ' ' / g, '<strong>$1</strong>' )
252- // Replace double newlines with paragraphs
253- . split ( / (?: \r ? \n ) / g)
254- . map ( ( line ) => {
255- let ret = ''
256- if ( listStarted && ! rasterisks . test ( line ) ) {
257- listStarted = false
258- ret += '</ul>'
259- }
260- if ( ! line . trim ( ) ) {
261- return ret
262- }
263- if ( line . startsWith ( '<pre' ) ) {
264- return ret + line
265- }
266- // Blockquotes
267- if ( line . startsWith ( '> ' ) ) {
268- return ret + `<blockquote>${ line . slice ( 2 ) } </blockquote>`
269- }
270- // Headers
271- if ( rheaders . test ( line ) ) {
272- return (
273- ret +
274- line . replace ( rheaders , ( _all , equals , content ) => {
275- const level = equals . length
276- return `<h${ level } >${ content } </h${ level } >`
277- } )
278- )
279- }
280- if ( rasterisks . test ( line ) ) {
281- line = line . replace (
282- / ( ^ | \s + ) \* ( [ ^ \n ] + ) / g,
283- `$1${ listStarted ? '' : '<ul>' } <li>$2</li>`
284- )
285- listStarted = true
286- return ret + line
287- }
288- return ret + `<p>${ line } </p>`
289- } )
290- . join ( '' )
291- // Reinsert code
292- . replace ( / < c o d e > < \/ c o d e > / g, ( ) => {
293- const code = codes . shift ( )
294- return `<code>${ code } </code>`
295- } )
296- // Reinsert pres
297- . replace ( / < p r e c l a s s = " w i k i " > < \/ p r e > / g, ( ) => {
298- const code = pres . shift ( )
299- return `<pre class="wiki">${ code } </pre>`
300- } )
301- )
302- } )
159+ eleventyConfig . addFilter ( 'tracToHTML' , tracToHTML )
303160
304161 // Shortcodes
305162 eleventyConfig . addShortcode ( 'currentYear' , ( ) => {
0 commit comments