@raspberrypifoundation/rpf-markdown-core 0.1.0 → 0.1.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.
package/dist/index.cjs CHANGED
@@ -976,7 +976,35 @@ function createLegacyBlockExtension(name, blockName, render, appendNewline = tru
976
976
  }
977
977
  };
978
978
  }
979
+ function canUseHtmlRenderer(content) {
980
+ return /^\s*(?:<!doctype\b|<!--|<(?:article|aside|blockquote|br|code|details|div|dl|figure|footer|h[1-6]|header|hr|main|nav|ol|p|pre|section|table|ul)\b)/i.test(
981
+ content
982
+ );
983
+ }
984
+ function serializeHtmlRendererNode(node) {
985
+ if ("outerHTML" in node && typeof node.outerHTML === "string") {
986
+ return node.outerHTML;
987
+ }
988
+ if (node.nodeType === 8) {
989
+ return `<!--${node.textContent ?? ""}-->`;
990
+ }
991
+ return node.textContent ?? "";
992
+ }
993
+ function serializeHtmlRendererOutput(fragment) {
994
+ return Array.from(fragment.childNodes).map(serializeHtmlRendererNode).join("");
995
+ }
996
+ function processHtmlContent(content) {
997
+ if (typeof document === "undefined") {
998
+ return applyInlineCodeClasses(content);
999
+ }
1000
+ const template = document.createElement("template");
1001
+ template.innerHTML = content;
1002
+ return applyInlineCodeClasses(serializeHtmlRendererOutput(template.content));
1003
+ }
979
1004
  function processEditorProject(content) {
1005
+ if (canUseHtmlRenderer(content)) {
1006
+ return processHtmlContent(content);
1007
+ }
980
1008
  import_marked2.marked.use(markedSmartypantsLite());
981
1009
  import_marked2.marked.use({
982
1010
  extensions: [
package/dist/index.js CHANGED
@@ -941,7 +941,35 @@ function createLegacyBlockExtension(name, blockName, render, appendNewline = tru
941
941
  }
942
942
  };
943
943
  }
944
+ function canUseHtmlRenderer(content) {
945
+ return /^\s*(?:<!doctype\b|<!--|<(?:article|aside|blockquote|br|code|details|div|dl|figure|footer|h[1-6]|header|hr|main|nav|ol|p|pre|section|table|ul)\b)/i.test(
946
+ content
947
+ );
948
+ }
949
+ function serializeHtmlRendererNode(node) {
950
+ if ("outerHTML" in node && typeof node.outerHTML === "string") {
951
+ return node.outerHTML;
952
+ }
953
+ if (node.nodeType === 8) {
954
+ return `<!--${node.textContent ?? ""}-->`;
955
+ }
956
+ return node.textContent ?? "";
957
+ }
958
+ function serializeHtmlRendererOutput(fragment) {
959
+ return Array.from(fragment.childNodes).map(serializeHtmlRendererNode).join("");
960
+ }
961
+ function processHtmlContent(content) {
962
+ if (typeof document === "undefined") {
963
+ return applyInlineCodeClasses(content);
964
+ }
965
+ const template = document.createElement("template");
966
+ template.innerHTML = content;
967
+ return applyInlineCodeClasses(serializeHtmlRendererOutput(template.content));
968
+ }
944
969
  function processEditorProject(content) {
970
+ if (canUseHtmlRenderer(content)) {
971
+ return processHtmlContent(content);
972
+ }
945
973
  marked2.use(markedSmartypantsLite());
946
974
  marked2.use({
947
975
  extensions: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raspberrypifoundation/rpf-markdown-core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "registry": "https://npm.pkg.github.com"
24
24
  },
25
25
  "scripts": {
26
- "build": "tsup src/index.ts --format esm,cjs --dts",
26
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
27
27
  "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
28
28
  "test": "vitest run",
29
29
  "prepack": "npm run build"
@@ -46,5 +46,6 @@
46
46
  "tsx": "^4.21.0",
47
47
  "typescript": "^6.0.2",
48
48
  "vitest": "^4.1.2"
49
- }
49
+ },
50
+ "packageManager": "yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8"
50
51
  }