@lowlighter/markdown 1.2.3 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +31 -33
  2. package/mod.d.ts +34 -0
  3. package/mod.js +22 -0
  4. package/package.json +117 -40
  5. package/plugins/anchors.d.ts +11 -0
  6. package/plugins/anchors.js +39 -0
  7. package/plugins/callouts.d.ts +14 -0
  8. package/plugins/callouts.js +31 -0
  9. package/plugins/directives.d.ts +24 -0
  10. package/plugins/directives.js +76 -0
  11. package/plugins/emojis.d.ts +11 -0
  12. package/plugins/emojis.js +15 -0
  13. package/plugins/frontmatter.d.ts +20 -0
  14. package/plugins/frontmatter.js +49 -0
  15. package/plugins/gfm.d.ts +18 -0
  16. package/plugins/gfm.js +43 -0
  17. package/plugins/{highlighting.ts → highlighting.d.ts} +2 -11
  18. package/plugins/highlighting.js +24 -0
  19. package/plugins/markers.d.ts +15 -0
  20. package/plugins/markers.js +30 -0
  21. package/plugins/math.d.ts +21 -0
  22. package/plugins/math.js +75 -0
  23. package/plugins/mermaid.d.ts +25 -0
  24. package/plugins/mermaid.js +32 -0
  25. package/plugins/mod.d.ts +15 -0
  26. package/plugins/mod.js +14 -0
  27. package/plugins/{ruby.ts → ruby.d.ts} +2 -11
  28. package/plugins/ruby.js +28 -0
  29. package/plugins/uncomments.d.ts +13 -0
  30. package/plugins/uncomments.js +28 -0
  31. package/plugins/wikilinks.d.ts +26 -0
  32. package/plugins/wikilinks.js +45 -0
  33. package/presets/default.d.ts +3 -0
  34. package/presets/default.js +9 -0
  35. package/presets/svg.d.ts +3 -0
  36. package/presets/svg.js +11 -0
  37. package/presets/text.d.ts +3 -0
  38. package/presets/text.js +11 -0
  39. package/presets/web.d.ts +3 -0
  40. package/presets/web.js +12 -0
  41. package/renderer.d.ts +62 -0
  42. package/renderer.js +70 -0
  43. package/types.d.ts +85 -0
  44. package/types.js +10 -0
  45. package/deno.jsonc +0 -124
  46. package/deno.lock +0 -2393
  47. package/mod.mjs +0 -1
  48. package/mod.ts +0 -2
  49. package/mod_test.ts +0 -1
  50. package/plugins/anchors.mjs +0 -1
  51. package/plugins/anchors.ts +0 -21
  52. package/plugins/anchors_test.ts +0 -8
  53. package/plugins/directives.mjs +0 -1
  54. package/plugins/directives.ts +0 -112
  55. package/plugins/directives_test.ts +0 -13
  56. package/plugins/emojis.mjs +0 -1
  57. package/plugins/emojis.ts +0 -20
  58. package/plugins/emojis_test.ts +0 -8
  59. package/plugins/frontmatter.mjs +0 -1
  60. package/plugins/frontmatter.ts +0 -43
  61. package/plugins/frontmatter_test.ts +0 -18
  62. package/plugins/gfm.mjs +0 -1
  63. package/plugins/gfm.ts +0 -14
  64. package/plugins/gfm_test.ts +0 -28
  65. package/plugins/highlighting.mjs +0 -1
  66. package/plugins/highlighting_test.ts +0 -8
  67. package/plugins/linebreaks.mjs +0 -1
  68. package/plugins/linebreaks.ts +0 -21
  69. package/plugins/linebreaks_test.ts +0 -8
  70. package/plugins/markers.mjs +0 -1
  71. package/plugins/markers.ts +0 -25
  72. package/plugins/markers_test.ts +0 -13
  73. package/plugins/math.mjs +0 -1
  74. package/plugins/math.ts +0 -25
  75. package/plugins/math_test.ts +0 -8
  76. package/plugins/mermaid.mjs +0 -1
  77. package/plugins/mermaid.ts +0 -41
  78. package/plugins/mermaid_test.ts +0 -8
  79. package/plugins/mod.mjs +0 -1
  80. package/plugins/mod.ts +0 -14
  81. package/plugins/ruby.mjs +0 -1
  82. package/plugins/ruby_test.ts +0 -8
  83. package/plugins/sanitize.mjs +0 -1
  84. package/plugins/sanitize.ts +0 -26
  85. package/plugins/sanitize_test.ts +0 -15
  86. package/plugins/uncomments.mjs +0 -1
  87. package/plugins/uncomments.ts +0 -20
  88. package/plugins/uncomments_test.ts +0 -8
  89. package/plugins/wikilinks.mjs +0 -1
  90. package/plugins/wikilinks.ts +0 -40
  91. package/plugins/wikilinks_test.ts +0 -14
  92. package/renderer.mjs +0 -1
  93. package/renderer.ts +0 -138
  94. package/renderer_test.ts +0 -19
@@ -1,21 +0,0 @@
1
- // Imports
2
- import type { Plugin } from "../renderer.ts"
3
- import remarkBreaks from "remark-breaks"
4
-
5
- /**
6
- * Force line-breaks to be hard-breaks.
7
- *
8
- * @example
9
- * ```md
10
- * foo
11
- * bar
12
- * ```
13
- * ```html
14
- * <p>foo<br>bar</p>
15
- * ```
16
- */
17
- export default {
18
- remark(processor) {
19
- return processor.use(remarkBreaks)
20
- },
21
- } as Plugin
@@ -1,8 +0,0 @@
1
- import { expect, test } from "@libs/testing"
2
- import { Renderer } from "../renderer.ts"
3
- import plugin from "./linebreaks.ts"
4
-
5
- test("deno")("Plugin.linebreaks renders hard linebreaks", async () => {
6
- const markdown = new Renderer({ plugins: [plugin] })
7
- await expect(markdown.render("foo\nbar")).resolves.toMatch(/foo<br>\nbar/)
8
- })
@@ -1 +0,0 @@
1
- var e=function(n){if(null==n)return t;if("function"==typeof n)return r(n);if("object"==typeof n)return Array.isArray(n)?function(t){const n=[];let i=-1;for(;++i<t.length;)n[i]=e(t[i]);return r(o);function o(...e){let r=-1;for(;++r<n.length;)if(n[r].apply(this,e))return!0;return!1}}(n):function(e){const t=e;return r(n);function n(r){const n=r;let i;for(i in e)if(n[i]!==t[i])return!1;return!0}}(n);if("string"==typeof n)return function(e){return r(t);function t(r){return r&&r.type===e}}(n);throw new Error("Expected function, string, or object as test")};function r(e){return function(r,t,n){return Boolean(function(e){return null!==e&&"object"==typeof e&&"type"in e}(r)&&e.call(this,r,"number"==typeof t?t:void 0,n||void 0))}}function t(){return!0}var n=[],i=!0,o=!1,c="skip";function s(r,t,s,l){let a;"function"==typeof t&&"function"!=typeof s?(l=s,s=t):a=t;const f=e(a),u=l?-1:1;!function e(r,a,d){const h=r&&"object"==typeof r?r:{};if("string"==typeof h.type){const e="string"==typeof h.tagName?h.tagName:"string"==typeof h.name?h.name:void 0;Object.defineProperty(p,"name",{value:"node ("+r.type+(e?"<"+e+">":"")+")"})}return p;function p(){let h,p,m,y=n;if((!t||f(r,a,d[d.length-1]||void 0))&&(y=function(e){if(Array.isArray(e))return e;if("number"==typeof e)return[i,e];return null==e?n:[e]}(s(r,d)),y[0]===o))return y;if("children"in r&&r.children){const t=r;if(t.children&&y[0]!==c)for(p=(l?t.children.length:-1)+u,m=d.concat(t);p>-1&&p<t.children.length;){const r=t.children[p];if(h=e(r,p,m)(),h[0]===o)return h;p="number"==typeof h[1]?h[1]:p+u}}return y}}(r,void 0,[])()}function l(e,r,t,n){let i,o,c;"function"==typeof r&&"function"!=typeof t?(o=void 0,c=r,i=t):(o=r,c=t,i=n),s(e,o,(function(e,r){const t=r[r.length-1],n=t?t.children.indexOf(e):void 0;return c(e,n,t)}),i)}function a(e,r,t){const n={type:String(e)};return null!=t||"string"!=typeof r&&!Array.isArray(r)?Object.assign(n,r):t=r,Array.isArray(t)?n.children=t:null!=t&&(n.value=String(t)),n}var f={a:"amber",b:"blue",c:"cyan",d:"brown",e:"espresso",f:"fuchsia",g:"green",h:"hotpink",i:"indigo",j:"jade",k:"kiwi",l:"lime",m:"magenta",n:"navyblue",o:"orange",p:"purple",q:"pink",r:"red",s:"silver",t:"teal",u:"umber",v:"violet",w:"white",x:"gray",y:"yellow",z:"black"},u={dictionary:f,markerTagName:"mark",markerClassName:"flexible-marker",actionForEmptyContent:"mark"},d=/=([a-z]?)=(?![\s=])([\s\S]*?)(?<![\s=])==/,h=/=([a-z]?)=(?![\s=])([\s\S]*?)(?<![\s=])==/g,p=/=([a-z]?)=(?![\s]|=+\s)/,m=/=([a-z]?)=(?![\s]|=+\s)/g,y=/(?<!\s|\s=|\s==|\s===|\s====)==/,g=/(?<!\s|\s=|\s==|\s===|\s====)==/g,x=/=([a-z]?)=\s*==/,v=/=([a-z]?)=\s*==/g;var b=r=>{const t=Object.assign({},u,r);r?.dictionary&&Object.keys(r.dictionary).length&&(t.dictionary=Object.assign({},f,r.dictionary));const n=(e,r)=>{let n;const i=e?t.dictionary[e]:void 0,o="string"==typeof t.markerTagName?t.markerTagName:t.markerTagName(i),c="function"==typeof t.markerClassName?t.markerClassName(i):[t.markerClassName,!e&&`${t.markerClassName}-default`,i&&`${t.markerClassName}-${i}`,!r.length&&`${t.markerClassName}-empty`].filter((e=>!!e));return t.markerProperties&&(n=t.markerProperties(i),Object.entries(n).forEach((([e,r])=>{("string"==typeof r&&""===r||Array.isArray(r)&&0===r.length)&&n&&(n[e]=void 0),"className"===e&&delete n?.className}))),{type:"mark",children:r,data:{hName:o,hProperties:{className:c,...n&&{...n}}}}},o=function(e,r,t){if(!t||void 0===r)return;if(!d.test(e.value))return;const i=[],o=e.value;let c="",s=0,l=0;const f=Array.from(o.matchAll(h));for(let e=0;e<f.length;e++){const r=f[e],[t,u,d]=r,h=r.index,p=t.length,m=s+l;if(s=h,l=p,h>m){const e=a("text",o.substring(m,h));i.push(e)}const y=n(u,[{type:"text",value:d.trim()}]);i.push(y),c=o.slice(h+p)}if(c){const e=a("text",c);i.push(e)}i.length&&t.children.splice(r,1,...i)},s=function(r,t,i){if(!i||void 0===t)return;if(!p.test(r.value))return;const o=r,c=function(r,t,n){const i=e(n);if(!r||!r.type||!r.children)throw new Error("Expected parent node");if("number"==typeof t){if(t<0||t===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index")}else if((t=r.children.indexOf(t))<0)throw new Error("Expected child node or index");for(;++t<r.children.length;)if(i(r.children[t],t,r))return r.children[t]}(i,o,(function(e){return"text"===e.type&&y.test(e.value)}));if(!c)return;const s=function(r,t,n){const i=e(n),o=[];let c=-1;if(!r||!r.type||!r.children)throw new Error("Expected parent node");if("number"==typeof t){if(t<0||t===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index")}else if((t=r.children.indexOf(t))<0)throw new Error("Expected child node or index");for(t>r.children.length&&(t=r.children.length);++c<t;)i(r.children[c],c,r)&&o.push(r.children[c]);return o}(i,o),l=function(r,t,n,i,o){const c=e(i),s=[];if(!r||!r.type||!r.children)throw new Error("Expected parent node");if("number"==typeof t){if(t<0||t===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index for start")}else if((t=r.children.indexOf(t))<0)throw new Error("Expected child node or index for start");if("number"==typeof n){if(n<0||n===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index for end")}else if((n=r.children.indexOf(n))<0)throw new Error("Expected child node or index for end");if("include"===o?.behaviour)for(;t<=n;)c(r.children[t],t,r)&&s.push(r.children[t]),t++;else for(;++t<n;)c(r.children[t],t,r)&&s.push(r.children[t]);return s}(i,o,c),f=function(r,t,n){const i=e(n),o=[];if(!r||!r.type||!r.children)throw new Error("Expected parent node");if("number"==typeof t){if(t<0||t===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index")}else if((t=r.children.indexOf(t))<0)throw new Error("Expected child node or index");for(;++t<r.children.length;)i(r.children[t],t,r)&&o.push(r.children[t]);return o}(i,c),u=o.value,d=Array.from(u.matchAll(m))[0],[h,x]=d,v=h.length,b=d.index;if(b>0){const e=a("text",u.substring(0,b));s.push(e)}if(u.length>b+v){const e=a("text",u.slice(b+v));l.unshift(e)}const E=c.value,w=Array.from(E.matchAll(g))[0],[N]=w,k=N.length,I=w.index;if(I>0){const e=a("text",E.substring(0,I));l.push(e)}if(E.length>I+k){const e=a("text",E.slice(I+k));f.unshift(e)}const A=n(x,l);return i.children=[...s,A,...f],t},b=function(e,r,o){if(!o||void 0===r)return;if(!x.test(e.value))return;if("remove"===t.actionForEmptyContent)return e.value=e.value.replaceAll(v,""),""===e.value.trim()?[c,r]:i;const s=[],l=e.value;let f="",u=0,d=0;const h=Array.from(l.matchAll(v));for(let e=0;e<h.length;e++){const r=h[e],[t,i]=r,o=r.index,c=t.length,p=u+d;if(u=o,d=c,o>p){const e=a("text",l.substring(p,o));s.push(e)}const m=n(i,[]);s.push(m),f=l.slice(o+c)}if(f){const e=a("text",f);s.push(e)}s.length&&o.children.splice(r,1,...s)};return e=>{if(l(e,"text",o),l(e,"text",s),"keep"!==t.actionForEmptyContent&&l(e,"text",b),t.equalityOperator){const r=new RegExp(t.equalityOperator,"gi");l(e,"text",(e=>{e.value=e.value.replaceAll(r,"==")}))}}},E=Object.fromEntries([..."abcdefghijklmnopqrstuvwxyz"].map((e=>[e,e]))),w={remark:e=>e.use(b,{dictionary:E,markerClassName:()=>[],markerProperties:e=>e?{[e]:!0}:{}})};export{w as default};
@@ -1,25 +0,0 @@
1
- // Imports
2
- import type { Plugin } from "../renderer.ts"
3
- import remarkFlexibleMarkers from "remark-flexible-markers"
4
-
5
- /** Marker attributes */
6
- const dictionary = Object.fromEntries([..."abcdefghijklmnopqrstuvwxyz"].map((letter) => [letter, letter]))
7
-
8
- /**
9
- * Add support for markers.
10
- *
11
- * @example
12
- * ```md
13
- * ==foo==
14
- * =r=bar=
15
- * ```
16
- * ```html
17
- * <p><mark>foo</mark></p>
18
- * <p><mark r>bar</mark></p>
19
- * ```
20
- */
21
- export default {
22
- remark(processor) {
23
- return processor.use(remarkFlexibleMarkers, { dictionary, markerClassName: () => [], markerProperties: (letter) => (letter ? { [letter]: true } : {}) })
24
- },
25
- } as Plugin
@@ -1,13 +0,0 @@
1
- import { expect, test } from "@libs/testing"
2
- import { Renderer } from "../renderer.ts"
3
- import plugin from "./markers.ts"
4
-
5
- test("deno")("Plugin.markers renders markers", async () => {
6
- const markdown = new Renderer({ plugins: [plugin] })
7
- await expect(markdown.render("==foo==")).resolves.toMatch(/<mark class="">foo<\/mark>/)
8
- })
9
-
10
- test("deno")("Plugin.markers renders colored markers", async () => {
11
- const markdown = new Renderer({ plugins: [plugin] })
12
- await expect(markdown.render("=r=foo==")).resolves.toMatch(/<mark class="" r="">foo<\/mark>/)
13
- })