@rakutentech/docsify-code-inline
Advanced tools
Comparing version 1.0.4 to 1.0.5
# @rakutentech/docsify-code-inline ChangeLog | ||
## v1.0.5 | ||
_2021-01-21_ | ||
### Bugfixes | ||
- fix: changed format from cjs to iife (20705b9) | ||
- fix: add missing transformation result to readme (6916392) | ||
## v1.0.4 | ||
@@ -4,0 +13,0 @@ |
@@ -1,15 +0,14 @@ | ||
'use strict'; | ||
var docsifyCodeInline = (function (exports) { | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _a, _b, _c, _d; | ||
// Core | ||
function transform(markdown) { | ||
const RE = /\[`(.*?)(?<!\\(\\{2})*)`\s+([a-z0-9-]+?)\](?!\()/g; | ||
return markdown.replace(RE, (_, code, __, lang) => { | ||
const escaped = code.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | ||
return `<code class="language-${lang}">${escaped}</code>`; | ||
}); | ||
} | ||
const DEFAULT_CSS = ` | ||
var _a, _b, _c, _d; | ||
// Core | ||
function transform(markdown) { | ||
const RE = /\[`(.*?)(?<!\\(\\{2})*)`\s+([a-z0-9-]+?)\](?!\()/g; | ||
return markdown.replace(RE, (_, code, __, lang) => { | ||
const escaped = code.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | ||
return `<code class="language-${lang}">${escaped}</code>`; | ||
}); | ||
} | ||
const DEFAULT_CSS = ` | ||
.markdown-section :not(pre) > code[class*="language-"] { | ||
@@ -23,23 +22,29 @@ background: var(--code-theme-background); | ||
`; | ||
// Plugin registration and CSS injection need a DOM | ||
if (typeof document !== 'undefined') { | ||
// Register the plugin automatically, unless <script data-no-autoload> was used | ||
if (typeof ((_b = (_a = document.currentScript) === null || _a === void 0 ? void 0 : _a.dataset) === null || _b === void 0 ? void 0 : _b.noAutoload) === 'undefined') { | ||
const inlineCode = (hook) => { | ||
hook.beforeEach((content) => transform(content)); | ||
}; | ||
$docsify = $docsify || {}; | ||
$docsify.plugins = $docsify.plugins || []; | ||
$docsify.plugins.push(inlineCode); | ||
} | ||
// Add CSS automatically, unless <script data-no-css-inject> was used | ||
if (typeof ((_d = (_c = document.currentScript) === null || _c === void 0 ? void 0 : _c.dataset) === null || _d === void 0 ? void 0 : _d.noCssInject) === 'undefined') { | ||
document.head | ||
.insertBefore(document.createElement('style'), document.head.firstElementChild) | ||
.appendChild(document.createTextNode(DEFAULT_CSS)); | ||
} | ||
} | ||
// Plugin registration and CSS injection need a DOM | ||
if (typeof document !== 'undefined') { | ||
// Register the plugin automatically, unless <script data-no-autoload> was used | ||
if (typeof ((_b = (_a = document.currentScript) === null || _a === void 0 ? void 0 : _a.dataset) === null || _b === void 0 ? void 0 : _b.noAutoload) === 'undefined') { | ||
const inlineCode = (hook) => { | ||
hook.beforeEach((content) => transform(content)); | ||
}; | ||
$docsify = $docsify || {}; | ||
$docsify.plugins = $docsify.plugins || []; | ||
$docsify.plugins.push(inlineCode); | ||
} | ||
// Add CSS automatically, unless <script data-no-css-inject> was used | ||
if (typeof ((_d = (_c = document.currentScript) === null || _c === void 0 ? void 0 : _c.dataset) === null || _d === void 0 ? void 0 : _d.noCssInject) === 'undefined') { | ||
document.head | ||
.insertBefore(document.createElement('style'), document.head.firstElementChild) | ||
.appendChild(document.createTextNode(DEFAULT_CSS)); | ||
} | ||
} | ||
exports.DEFAULT_CSS = DEFAULT_CSS; | ||
exports.transform = transform; | ||
exports.DEFAULT_CSS = DEFAULT_CSS; | ||
exports.transform = transform; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
return exports; | ||
}({})); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var e,n,o,d;function r(e){return e.replace(/\[`(.*?)(?<!\\(\\{2})*)`\s+([a-z0-9-]+?)\](?!\()/g,((e,n,o,d)=>`<code class="language-${d}">${n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}</code>`))}Object.defineProperty(exports,"__esModule",{value:!0});const c='\n.markdown-section :not(pre) > code[class*="language-"] {\n background: var(--code-theme-background);\n margin: var(--code-inline-margin);\n padding: var(--code-inline-padding);\n border-radius: var(--code-inline-border-radius);\n color: var(--code-inline-color, currentColor);\n}\n';if("undefined"!=typeof document){if(void 0===(null===(n=null===(e=document.currentScript)||void 0===e?void 0:e.dataset)||void 0===n?void 0:n.noAutoload)){const e=e=>{e.beforeEach((e=>r(e)))};$docsify=$docsify||{},$docsify.plugins=$docsify.plugins||[],$docsify.plugins.push(e)}void 0===(null===(d=null===(o=document.currentScript)||void 0===o?void 0:o.dataset)||void 0===d?void 0:d.noCssInject)&&document.head.insertBefore(document.createElement("style"),document.head.firstElementChild).appendChild(document.createTextNode(c))}exports.DEFAULT_CSS=c,exports.transform=r; | ||
var docsifyCodeInline=function(e){"use strict";var n,o,d,r;function i(e){return e.replace(/\[`(.*?)(?<!\\(\\{2})*)`\s+([a-z0-9-]+?)\](?!\()/g,((e,n,o,d)=>`<code class="language-${d}">${n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}</code>`))}const c='\n.markdown-section :not(pre) > code[class*="language-"] {\n background: var(--code-theme-background);\n margin: var(--code-inline-margin);\n padding: var(--code-inline-padding);\n border-radius: var(--code-inline-border-radius);\n color: var(--code-inline-color, currentColor);\n}\n';if("undefined"!=typeof document){if(void 0===(null===(o=null===(n=document.currentScript)||void 0===n?void 0:n.dataset)||void 0===o?void 0:o.noAutoload)){const e=e=>{e.beforeEach((e=>i(e)))};$docsify=$docsify||{},$docsify.plugins=$docsify.plugins||[],$docsify.plugins.push(e)}void 0===(null===(r=null===(d=document.currentScript)||void 0===d?void 0:d.dataset)||void 0===r?void 0:r.noCssInject)&&document.head.insertBefore(document.createElement("style"),document.head.firstElementChild).appendChild(document.createTextNode(c))}return e.DEFAULT_CSS=c,e.transform=i,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@rakutentech/docsify-code-inline", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public", |
@@ -60,4 +60,11 @@ [npm]: https://img.shields.io/npm/v/@rakutentech/docsify-code-inline | ||
…produces the following DOM tree when PrismJS is loaded with HTML support: | ||
…gets transformed by this plugin into: | ||
```html | ||
If you wrap `code` with square brackets and add a language identifier, e.g. <code class="language-html"><link href="foo"></code>, then the produced markup will | ||
enable syntax highlighting using PrismJS like in code fences. | ||
``` | ||
…which produces the following DOM tree when PrismJS is active and supports HTML: | ||
<!-- prettier-ignore --> | ||
@@ -64,0 +71,0 @@ ```html |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
17691
104
128