|
| 1 | +// import { |
| 2 | +// getAndRemoveConfig, |
| 3 | +// removeAtag, |
| 4 | +// getAndRemoveDocisfyIgnoreConfig, |
| 5 | +// } from '../utils.js'; |
| 6 | +// import { slugify } from './slugify.js'; |
| 7 | +// import { helper as helperTpl } from '../tpl.js'; |
| 8 | + |
| 9 | +// const default_renderer = { |
| 10 | +// space() { |
| 11 | +// return ''; |
| 12 | +// }, |
| 13 | + |
| 14 | +// code({ code, lang = 'markup' }) { |
| 15 | +// const langOrMarkup = Prism.languages[lang] || Prism.languages.markup; |
| 16 | +// const text = Prism.highlight( |
| 17 | +// code.replace(/@DOCSIFY_QM@/g, '`'), |
| 18 | +// langOrMarkup, |
| 19 | +// lang, |
| 20 | +// ); |
| 21 | + |
| 22 | +// return /* html */ `<pre data-lang="${lang}"><code class="lang-${lang}" tabindex="0">${text}</code></pre>`; |
| 23 | +// }, |
| 24 | + |
| 25 | +// // blockquote({ tokens }) { |
| 26 | +// // const body = this.parser?.parse(tokens); |
| 27 | +// // return `<blockquote>\n${body}</blockquote>\n`; |
| 28 | +// // }, |
| 29 | + |
| 30 | +// // html({ text }) { |
| 31 | +// // return text; |
| 32 | +// // }, |
| 33 | + |
| 34 | +// heading({ text, depth }) { |
| 35 | +// let { str, config } = getAndRemoveConfig(text); |
| 36 | +// const nextToc = { depth, title: str }; |
| 37 | + |
| 38 | +// const { content, ignoreAllSubs, ignoreSubHeading } = |
| 39 | +// getAndRemoveDocisfyIgnoreConfig(str); |
| 40 | +// str = content.trim(); |
| 41 | + |
| 42 | +// nextToc.title = removeAtag(str); |
| 43 | +// nextToc.ignoreAllSubs = ignoreAllSubs; |
| 44 | +// nextToc.ignoreSubHeading = ignoreSubHeading; |
| 45 | + |
| 46 | +// const slug = slugify(config.id || str); |
| 47 | +// const url = router.toURL(router.getCurrentPath(), { id: slug }); |
| 48 | +// nextToc.slug = url; |
| 49 | +// _self.toc.push(nextToc); |
| 50 | + |
| 51 | +// return /* html */ `<h${level} id="${slug}"><a href="${url}" data-id="${slug}" class="anchor"><span>${str}</span></a></h${depth}>`; |
| 52 | +// }, |
| 53 | + |
| 54 | +// list(token) { |
| 55 | +// const ordered = token.ordered; |
| 56 | +// const start = token.start; |
| 57 | + |
| 58 | +// let body = ''; |
| 59 | +// for (let j = 0; j < token.items.length; j++) { |
| 60 | +// const item = token.items[j]; |
| 61 | +// body += this.listitem?.(item); |
| 62 | +// } |
| 63 | + |
| 64 | +// const type = ordered ? 'ol' : 'ul'; |
| 65 | +// const startAttr = ordered && start !== 1 ? ' start="' + start + '"' : ''; |
| 66 | +// return '<' + type + startAttr + '>\n' + body + '</' + type + '>\n'; |
| 67 | +// }, |
| 68 | + |
| 69 | +// listitem(item) { |
| 70 | +// let itemBody = ''; |
| 71 | +// if (item.task) { |
| 72 | +// const checkbox = this.checkbox?.({ checked: !!item.checked }); |
| 73 | +// if (item.loose) { |
| 74 | +// if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') { |
| 75 | +// item.tokens[0].text = checkbox + ' ' + item.tokens[0].text; |
| 76 | +// if ( |
| 77 | +// item.tokens[0].tokens && |
| 78 | +// item.tokens[0].tokens.length > 0 && |
| 79 | +// item.tokens[0].tokens[0].type === 'text' |
| 80 | +// ) { |
| 81 | +// item.tokens[0].tokens[0].text = |
| 82 | +// checkbox + ' ' + item.tokens[0].tokens[0].text; |
| 83 | +// } |
| 84 | +// } else { |
| 85 | +// item.tokens.unshift({ |
| 86 | +// type: 'text', |
| 87 | +// raw: checkbox + ' ', |
| 88 | +// text: checkbox + ' ', |
| 89 | +// }); |
| 90 | +// } |
| 91 | +// } else { |
| 92 | +// itemBody += checkbox + ' '; |
| 93 | +// } |
| 94 | +// } |
| 95 | + |
| 96 | +// itemBody += this.parser?.parse(item.tokens, !!item.loose); |
| 97 | + |
| 98 | +// return `<li>${itemBody}</li>\n`; |
| 99 | +// }, |
| 100 | + |
| 101 | +// paragraph({ tokens }) { |
| 102 | +// const text = this.parser?.parseInline(tokens); |
| 103 | +// let result; |
| 104 | +// if (/^!>/.test(text)) { |
| 105 | +// result = helperTpl('tip', text); |
| 106 | +// } else if (/^\?>/.test(text)) { |
| 107 | +// result = helperTpl('warn', text); |
| 108 | +// } else { |
| 109 | +// result = /* html */ `<p>${text}</p>`; |
| 110 | +// } |
| 111 | + |
| 112 | +// return result; |
| 113 | +// }, |
| 114 | + |
| 115 | +// table(token) { |
| 116 | +// let header = ''; |
| 117 | + |
| 118 | +// // header |
| 119 | +// let cell = ''; |
| 120 | +// for (let j = 0; j < token.header.length; j++) { |
| 121 | +// cell += this.tablecell?.(token.header[j]); |
| 122 | +// } |
| 123 | +// header += this.tablerow?.({ text: cell }); |
| 124 | + |
| 125 | +// let body = ''; |
| 126 | +// for (let j = 0; j < token.rows.length; j++) { |
| 127 | +// const row = token.rows[j]; |
| 128 | + |
| 129 | +// cell = ''; |
| 130 | +// for (let k = 0; k < row.length; k++) { |
| 131 | +// cell += this.tablecell?.(row[k]); |
| 132 | +// } |
| 133 | + |
| 134 | +// body += this.tablerow?.({ text: cell }); |
| 135 | +// } |
| 136 | +// if (body) body = `<tbody>${body}</tbody>`; |
| 137 | + |
| 138 | +// return ( |
| 139 | +// '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n' |
| 140 | +// ); |
| 141 | +// }, |
| 142 | + |
| 143 | +// tablerow({ text }) { |
| 144 | +// return `<tr>\n${text}</tr>\n`; |
| 145 | +// }, |
| 146 | + |
| 147 | +// tablecell(token) { |
| 148 | +// const content = this.parser?.parseInline(token.tokens); |
| 149 | +// const type = token.header ? 'th' : 'td'; |
| 150 | +// const tag = token.align ? `<${type} align="${token.align}">` : `<${type}>`; |
| 151 | +// return tag + content + `</${type}>\n`; |
| 152 | +// }, |
| 153 | + |
| 154 | +// /** |
| 155 | +// * span level renderer |
| 156 | +// */ |
| 157 | +// strong({ tokens }) { |
| 158 | +// return `<strong>${this.parser?.parseInline(tokens)}</strong>`; |
| 159 | +// }, |
| 160 | + |
| 161 | +// em({ tokens }) { |
| 162 | +// return `<em>${this.parser?.parseInline(tokens)}</em>`; |
| 163 | +// }, |
| 164 | + |
| 165 | +// codespan({ text }) { |
| 166 | +// return `<code>${text}</code>`; |
| 167 | +// }, |
| 168 | + |
| 169 | +// br(token) { |
| 170 | +// return '<br>'; |
| 171 | +// }, |
| 172 | + |
| 173 | +// del({ tokens }) { |
| 174 | +// return `<del>${this.parser?.parseInline(tokens)}</del>`; |
| 175 | +// }, |
| 176 | + |
| 177 | +// link({ href, title, tokens }) { |
| 178 | +// const text = this.parser?.parseInline(tokens) || ''; |
| 179 | +// const attrs = []; |
| 180 | +// const { str, config } = getAndRemoveConfig(title); |
| 181 | +// linkTarget = config.target || linkTarget; |
| 182 | +// linkRel = |
| 183 | +// linkTarget === '_blank' |
| 184 | +// ? compilerClass.config.externalLinkRel || 'noopener' |
| 185 | +// : ''; |
| 186 | +// title = str; |
| 187 | + |
| 188 | +// if ( |
| 189 | +// !isAbsolutePath(href) && |
| 190 | +// !compilerClass._matchNotCompileLink(href) && |
| 191 | +// !config.ignore |
| 192 | +// ) { |
| 193 | +// if (href === compilerClass.config.homepage) { |
| 194 | +// href = 'README'; |
| 195 | +// } |
| 196 | + |
| 197 | +// href = router.toURL(href, null, router.getCurrentPath()); |
| 198 | + |
| 199 | +// if (config.target) { |
| 200 | +// href.indexOf('mailto:') !== 0 && attrs.push(`target="${linkTarget}"`); |
| 201 | +// } |
| 202 | +// } else { |
| 203 | +// if (!isAbsolutePath(href) && href.slice(0, 2) === './') { |
| 204 | +// href = |
| 205 | +// document.URL.replace(/\/(?!.*\/).*/, '/').replace('#/./', '') + href; |
| 206 | +// } |
| 207 | +// attrs.push(href.indexOf('mailto:') === 0 ? '' : `target="${linkTarget}"`); |
| 208 | +// attrs.push( |
| 209 | +// href.indexOf('mailto:') === 0 |
| 210 | +// ? '' |
| 211 | +// : linkRel !== '' |
| 212 | +// ? ` rel="${linkRel}"` |
| 213 | +// : '', |
| 214 | +// ); |
| 215 | +// } |
| 216 | + |
| 217 | +// if (config.disabled) { |
| 218 | +// attrs.push('disabled'); |
| 219 | +// href = 'javascript:void(0)'; |
| 220 | +// } |
| 221 | + |
| 222 | +// if (config.class) { |
| 223 | +// attrs.push(`class="${config.class}"`); |
| 224 | +// } |
| 225 | + |
| 226 | +// if (config.id) { |
| 227 | +// attrs.push(`id="${config.id}"`); |
| 228 | +// } |
| 229 | + |
| 230 | +// if (title) { |
| 231 | +// attrs.push(`title="${title}"`); |
| 232 | +// } |
| 233 | + |
| 234 | +// return /* html */ `<a href="${href}" ${attrs.join(' ')}>${text}</a>`; |
| 235 | +// }, |
| 236 | + |
| 237 | +// image({ href, title, text }) { |
| 238 | +// const cleanHref = cleanUrl(href); |
| 239 | +// if (cleanHref === null) { |
| 240 | +// return text; |
| 241 | +// } |
| 242 | +// href = cleanHref; |
| 243 | + |
| 244 | +// let out = `<img src="${href}" alt="${text}"`; |
| 245 | +// if (title) { |
| 246 | +// out += ` title="${title}"`; |
| 247 | +// } |
| 248 | +// out += '>'; |
| 249 | +// return out; |
| 250 | +// }, |
| 251 | + |
| 252 | +// text(token) { |
| 253 | +// return 'tokens' in token && token.tokens |
| 254 | +// ? this.parser?.parseInline(token.tokens) || '' |
| 255 | +// : token.text; |
| 256 | +// }, |
| 257 | +// }; |
| 258 | + |
| 259 | +// /** @type {import('marked').TokenizerObject} */ |
| 260 | +// const tokenizer = { |
| 261 | +// url(src) { |
| 262 | +// // if `src` is a package version string, eg: [email protected] |
| 263 | +// // do not tokenize it as email |
| 264 | +// if (/@\d+\.\d+\.\d+/.test(src)) { |
| 265 | +// return undefined; |
| 266 | +// } |
| 267 | +// // else, use the default tokenizer behavior |
| 268 | +// return false; |
| 269 | +// }, |
| 270 | +// }; |
0 commit comments