diff --git a/docs/helpers.md b/docs/helpers.md index b047d36..9075448 100644 --- a/docs/helpers.md +++ b/docs/helpers.md @@ -7,24 +7,72 @@ docsify extends Markdown syntax to make your documents more readable. Important content like: ```markdown -!> **Time** is money, my friend! +> [!] **Time** is money, my friend! ``` is rendered as: -!> **Time** is money, my friend! +> [!] **Time** is money, my friend! ## General tips General tips like: ```markdown -?> _TODO_ unit test +> [?] _TODO_ unit test ``` are rendered as: -?> _TODO_ unit test +> [?] _TODO_ unit test + +## More tips + +```markdown +> [x] bad + +> [v] good +``` + +> [x] bad + +> [v] good + +## Details + +````markdown +> [details] Sample code +> +> js code +> +> ```javascript +> console.log("foo"); +> ``` + +> [details:open] Sample code open +> +> js code +> +> ```javascript +> console.log("foo"); +> ``` +```` + +> [details] Sample code +> +> js code +> +> ```javascript +> console.log("foo"); +> ``` + +> [details:open] Sample code open +> +> js code +> +> ```javascript +> console.log("foo"); +> ``` ## Ignore to compile link @@ -39,13 +87,13 @@ It will be compiled to `link` and will be loaded `/demo/R Now you can do that ```md -[link](/demo/ ':ignore') +[link](/demo/ ":ignore") ``` You will get `link`html. Do not worry, you can still set title for link. ```md -[link](/demo/ ':ignore title') +[link](/demo/ ":ignore title") link ``` @@ -53,14 +101,14 @@ You will get `link`html. Do not worry, you can still set ti ## Set target attribute for link ```md -[link](/demo ':target=_blank') -[link](/demo2 ':target=_self') +[link](/demo ":target=_blank") +[link](/demo2 ":target=_self") ``` ## Disable link ```md -[link](/demo ':disabled') +[link](/demo ":disabled") ``` ## Github Task Lists @@ -84,17 +132,17 @@ You will get `link`html. Do not worry, you can still set ti ## Image resizing ```md - - + + - + ``` - - - + + + ## Customise ID for headings diff --git a/docs/static.md b/docs/static.md index 1d4c7db..98bcb75 100644 --- a/docs/static.md +++ b/docs/static.md @@ -1,6 +1,6 @@ # Generate static html -_Experimental feature_ +> _Experimental feature_ Generating static html files is good for SEO and speeds up the first rendering. diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index e1b406b..502d938 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -1,6 +1,12 @@ import marked from 'marked' import Prism from 'prismjs' -import {helper as helperTpl, tree as treeTpl, cover as coverTpl} from './tpl' +import { + helper as helperTpl, + newHelper as newHelperTpl, + tree as treeTpl, + cover as coverTpl, + details as detailsTpl +} from './tpl' import {genTree} from './gen-tree' import {slugify} from './slugify' import {emojify} from './emojify' @@ -191,7 +197,7 @@ export class Compiler { /** * Render anchor tag - * @link https://github.com/markedjs/marked#overriding-renderer-methods + * @link https://marked.js.org/#/USING_PRO.md#renderer */ origin.heading = renderer.heading = function (text, level) { let {str, config} = getAndRemoveConfig(text) @@ -325,6 +331,46 @@ export class Compiler { return html } + origin.blockquote = renderer.blockquote = function (quote) { + const m = quote.match(/^\
(\[\S+\])/) + + if (m) { + const text = quote.replace(m[1], '') + switch (m[1]) { + case '[!]': + result = newHelperTpl('docsify-tip', text) + break + case '[?]': + result = newHelperTpl('docsify-warn', text) + break + case '[x]': + result = newHelperTpl('docsify-error', text) + break + case '[v]': + result = newHelperTpl('docsify-success', text) + break + case '[details]': + case '[details:open]': + let summary = false + const html = text.replace( + /^\
([^<]+)<\/p>([\s\S]+)/, + (m, m1, m2) => { + summary = m1 + return m2 + } + ) + const open = Boolean(/:open/.test(m[1])) + + result = detailsTpl({open, summary, html}) + break + default: + return quote + } + return result + } + + return quote + } renderer.origin = origin diff --git a/src/core/render/tpl.js b/src/core/render/tpl.js index 7cac6d2..a29f155 100644 --- a/src/core/render/tpl.js +++ b/src/core/render/tpl.js @@ -101,6 +101,17 @@ export function helper(className, content) { return `
${content.slice(5).trim()}
` } +export function newHelper(className, content) { + return `