@webmate-studio/builder 0.2.83 → 0.2.85

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/markdown.js +48 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webmate-studio/builder",
3
- "version": "0.2.83",
3
+ "version": "0.2.85",
4
4
  "type": "module",
5
5
  "description": "Webmate Studio Component Builder",
6
6
  "keywords": [
package/src/markdown.js CHANGED
@@ -19,12 +19,44 @@ marked.setOptions({
19
19
  mangle: false, // Email-Adressen nicht verschleiern
20
20
  });
21
21
 
22
+ /**
23
+ * Shift heading levels in HTML
24
+ * @param {string} html - HTML string
25
+ * @param {number} startLevel - The level that h1 should become (e.g., 2 means h1 → h2)
26
+ * @returns {string} HTML with shifted heading levels
27
+ */
28
+ function shiftHeadingLevels(html, startLevel) {
29
+ if (!startLevel || startLevel === 1) return html;
30
+
31
+ const offset = startLevel - 1;
32
+
33
+ // Shift headings (h1 → h2, h2 → h3, etc.)
34
+ // We need to do this in reverse order to avoid double-shifting
35
+ for (let level = 6; level >= 1; level--) {
36
+ const newLevel = Math.min(level + offset, 6);
37
+ if (newLevel !== level) {
38
+ // Replace opening and closing tags
39
+ html = html.replace(
40
+ new RegExp(`<h${level}(\\s|>)`, 'gi'),
41
+ `<h${newLevel}$1`
42
+ );
43
+ html = html.replace(
44
+ new RegExp(`</h${level}>`, 'gi'),
45
+ `</h${newLevel}>`
46
+ );
47
+ }
48
+ }
49
+
50
+ return html;
51
+ }
52
+
22
53
  /**
23
54
  * Konvertiert Markdown zu sicherem HTML
24
55
  *
25
56
  * @param {string} markdown - Markdown-String
26
57
  * @param {object} options - Optionale Konfiguration
27
58
  * @param {boolean} options.sanitize - HTML sanitizen (default: true)
59
+ * @param {number} options.headingStartLevel - Start level for headings (1-6, default: 1)
28
60
  * @returns {string} - Sicherer HTML-String
29
61
  */
30
62
  export function markdownToHtml(markdown, options = {}) {
@@ -35,6 +67,11 @@ export function markdownToHtml(markdown, options = {}) {
35
67
  // Markdown zu HTML
36
68
  let html = marked.parse(markdown);
37
69
 
70
+ // Shift heading levels if requested
71
+ if (options.headingStartLevel) {
72
+ html = shiftHeadingLevels(html, options.headingStartLevel);
73
+ }
74
+
38
75
  // XSS-Schutz mit DOMPurify
39
76
  if (options.sanitize !== false) {
40
77
  const config = {
@@ -66,9 +103,10 @@ export function markdownToHtml(markdown, options = {}) {
66
103
  *
67
104
  * @param {Object} props - Component props
68
105
  * @param {Object} propSchema - Prop schema with format info (from component.json)
106
+ * @param {Object} componentMetadata - Component metadata (for headingStartLevel, etc.)
69
107
  * @returns {Object} Props with markdown converted to HTML
70
108
  */
71
- export function processMarkdownProps(props, propSchema = null) {
109
+ export function processMarkdownProps(props, propSchema = null, componentMetadata = null) {
72
110
  if (!props || typeof props !== 'object') return props;
73
111
 
74
112
  const processed = { ...props };
@@ -81,8 +119,16 @@ export function processMarkdownProps(props, propSchema = null) {
81
119
  const isMarkdown = propSchema?.[key]?.format === 'markdown';
82
120
 
83
121
  if (isMarkdown) {
122
+ const options = {};
123
+
124
+ // Apply headingStartLevel from prop schema (preferred) or component metadata (fallback)
125
+ const headingStartLevel = propSchema?.[key]?.headingStartLevel || componentMetadata?.headingStartLevel;
126
+ if (headingStartLevel) {
127
+ options.headingStartLevel = headingStartLevel;
128
+ }
129
+
84
130
  // Convert markdown to HTML
85
- processed[key] = markdownToHtml(value);
131
+ processed[key] = markdownToHtml(value, options);
86
132
  }
87
133
  }
88
134