@miragon/slidev-toolkit 1.7.1 → 1.7.2

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.
@@ -31,6 +31,7 @@
31
31
  margin: 0;
32
32
  }
33
33
  .step-list.step-list :deep(p + p) { margin-top: 0.4em; }
34
+ .step-list.step-list :deep(.step__body > p) { display: inline; margin: 0; }
34
35
  .step-list.step-list :deep(strong) { font-weight: 700; color: var(--miragon-text-primary); }
35
36
  .step-list.step-list :deep(a) {
36
37
  color: var(--miragon-blue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miragon/slidev-toolkit",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "Miragon Slidev toolkit: the brand theme, the layout archetypes, the reusable components (Card, CardGrid, StepList, Figure, SplitView) and the BrandMeshBackground animation. Single source of design truth, consumed by the reference deck in this repo.",
5
5
  "keywords": [
6
6
  "slidev-theme",
@@ -0,0 +1,67 @@
1
+ import { defineTransformersSetup, defineMarkdownTransformer } from '@slidev/types'
2
+
3
+ /**
4
+ * Make inline Markdown render inside a component body, whatever the author wrote.
5
+ *
6
+ * Slidev only runs inline Markdown (`` `code` ``, **bold**, links) inside a
7
+ * component body when that body is its OWN Markdown block, i.e. separated from
8
+ * the opening/closing tags by blank lines. A body written on the tag line
9
+ * (`<Card title="X">`code`</Card>`) is handed through as raw HTML and the
10
+ * backticks/asterisks render literally. That is a silent footgun: the natural,
11
+ * one-line authoring form the deck otherwise mandates is exactly the form that
12
+ * breaks.
13
+ *
14
+ * This pre-transformer rewrites the single-line form into the blank-line form
15
+ * before the Markdown is parsed, so authors keep writing components on one line
16
+ * and inline Markdown just works:
17
+ *
18
+ * <Step label="Handle">`@Autowired ProcessEngine`.</Step>
19
+ *
20
+ * becomes, only for the parser:
21
+ *
22
+ * <Step label="Handle">
23
+ *
24
+ * `@Autowired ProcessEngine`.
25
+ *
26
+ * </Step>
27
+ *
28
+ * Paired with the `.step__body > p` rule in StepList.vue (which renders the
29
+ * resulting <p> inline) the step still reads as "Label: body" on one line.
30
+ *
31
+ * Scope is deliberately narrow: only the components whose default slot is a
32
+ * prose body, only when the whole `<Tag …>body</Tag>` sits on a single line
33
+ * (multi-line bodies are already blank-line blocks and are left untouched), and
34
+ * never inside fenced code blocks (so slides that *show* component source stay
35
+ * verbatim). Extend BODY_TAGS if another prose-body component is added.
36
+ */
37
+ const BODY_TAGS = ['Card', 'Step']
38
+
39
+ // <indent><Tag attrs>body</Tag> with body and close tag on the same line.
40
+ const SINGLE_LINE = new RegExp(
41
+ String.raw`^([ \t]*)<(${BODY_TAGS.join('|')})\b([^>\n]*)>(.+?)</\2>[ \t]*$`,
42
+ )
43
+ const FENCE = /^\s*(```|~~~)/
44
+
45
+ const wrapComponentBody = defineMarkdownTransformer((ctx) => {
46
+ const src = ctx.s.original
47
+ if (!src) return
48
+ const lines = src.split('\n')
49
+ let inFence = false
50
+ let changed = false
51
+ for (let i = 0; i < lines.length; i++) {
52
+ if (FENCE.test(lines[i])) {
53
+ inFence = !inFence
54
+ continue
55
+ }
56
+ if (inFence) continue
57
+ const m = lines[i].match(SINGLE_LINE)
58
+ if (!m) continue
59
+ const [, indent, tag, attrs, body] = m
60
+ if (!body.trim()) continue
61
+ lines[i] = `${indent}<${tag}${attrs}>\n\n${body.trim()}\n\n${indent}</${tag}>`
62
+ changed = true
63
+ }
64
+ if (changed) ctx.s.overwrite(0, src.length, lines.join('\n'))
65
+ })
66
+
67
+ export default defineTransformersSetup(() => ({ pre: [wrapComponentBody] }))