markawesome 0.16.0 → 0.18.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +51 -0
- data/README.md +7 -0
- data/lib/markawesome/icon_attributes.rb +17 -7
- data/lib/markawesome/plain_markdown_renderer.rb +11 -2
- data/lib/markawesome/transformer.rb +13 -0
- data/lib/markawesome/transformers/date_transformer.rb +209 -0
- data/lib/markawesome/transformers/icon_transformer.rb +2 -1
- data/lib/markawesome/transformers/popover_transformer.rb +32 -33
- data/lib/markawesome/transformers/random_content_transformer.rb +151 -0
- data/lib/markawesome/transformers/tabs_transformer.rb +20 -2
- data/lib/markawesome/transformers/tooltip_transformer.rb +18 -11
- data/lib/markawesome/transformers/tree_transformer.rb +163 -0
- data/lib/markawesome/transformers/video_transformer.rb +158 -0
- data/lib/markawesome/transformers.rb +4 -0
- data/lib/markawesome/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3ce7a2c074d2d33074977cfe3f20c474ba14908e4c07e283c8067e9adce65f4
|
|
4
|
+
data.tar.gz: 54c1bdd4ab2c53d11c14589757707b3325555afa5315142fa5341f6842d0b90a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae0b842c192958678ed64bca94c3f637d16c58c4c641c8cc02bc69234ca35e322fd4f677d424c959499c692a5b6f1c7acc477123ad86c3c4eb94a2c91c2ae654
|
|
7
|
+
data.tar.gz: d870d957d821ca0cd44c46a6afa7175d26436538ed3dae3ce2f7363afb8b1d20aa79a5195743fbfe7b47f5c7494402c89c32ce630acb6010d3f5fa91f1bb2b03
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,57 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.18.0] - 2026-07-04
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **`<wa-icon>` Web Awesome 3.10.0 attribute sync** — widens the shared icon vocabulary in `Markawesome::IconAttributes::SCHEMA` (used by both `$$$name` / `:::wa-icon …` **and**, transparently, callout icon overrides via `IconAttributes.pairs`, so the whole surface inherits it for free). Adds a **new `canvas` attribute** (`fixed`/`auto`/`square`/`roomy`; emitted only when specified — `fixed` is WA's default), a **new `semibold` variant** (alongside `thin light regular solid`), **nine new animations** (`flip-360`, `spin-snap`, `spin-snap-4`, `spin-snap-8`, `buzz`, `float`, `jello`, `swing`, `wag`), and a **full sync of the current WA family vocabulary** (`mosaic`, `pixel`, `vellum`, `slab-duo`, `slab-press-duo`, `chisel`, `etch`, `graphite`, `jelly`, `jelly-duo`, `jelly-fill`, `notdog`, `notdog-duo`, `slab`, `slab-press`, `thumbprint`, `utility`, `utility-duo`, `utility-fill`, `whiteboard` — family values are pure passthrough; whether one renders depends on the site's Font Awesome kit tier). The schema is a hard allowlist (`AttributeParser` silently drops unlisted tokens), so these values were previously unusable. **Deterministic emission order** is `family variant animation canvas` (`canvas` appended last) for byte-for-byte parity with `markawesome-js`. `auto-width` is unaffected — the engine never emitted it, and `canvas="auto"` is WA's supported replacement.
|
|
14
|
+
- New `RandomContentTransformer` producing Web Awesome's experimental `<wa-random-content>` — a container that shows one or more of its direct element children at random (optionally rotating them) and hides the rest, all in Web Awesome's own runtime. It gives an otherwise static site a "little bit dynamic" rotating tips / testimonials / featured-content block with **zero authored JavaScript**.
|
|
15
|
+
- **Primary syntax**: a `......` (6 dots) open fence carrying the params, options separated by a `>>>` line, closed by `......`. **Block alternative**: `:::wa-random-content <params>` … `>>>` … `:::`. The character space is nearly exhausted, so both glyphs are reused: `......` (six dots never occur in prose) and the **shared** `>>>` separator already used inside details/dialog/popover/tooltip.
|
|
16
|
+
- **Gated sigils**: `>>>` and `......` only act *inside* a `......`/`:::wa-random-content` block — a stray `>>>` or `...` in ordinary prose is inert. A line of exactly `>>>` or `......` inside an option is therefore a separator/close-fence; options cannot contain those literal lines (a hard constraint, like carousel's `~~~`).
|
|
17
|
+
- **Each option is wrapped in a single `<div>`** so Web Awesome sees exactly one selectable element child per option (a multi-paragraph option becomes one `<div>` with several `<p>` — precisely why the wrapper exists). Empty options are dropped (an empty rotating option would show nothing).
|
|
18
|
+
- **Params** (order-independent, on the opening fence line): `mode` (`unique` WA default / `random` / `sequence`, as a bare enum or `mode:VALUE`), `animation` (`none`/`fade`/`fade-up`/`fade-down`/`fade-left`/`fade-right`, bare or `animation:VALUE`), `autoplay` (bare boolean), `items` (a bare integer or `items:N`), and `autoplay-interval:N`. Bare enums/booleans are parsed by `AttributeParser`; `mode:`/`animation:` colon forms are enum-validated; unknown/invalid tokens are silently ignored. **Deterministic emission order** (for byte-parity with `markawesome-js`): `mode`, `items`, `animation`, `autoplay`, `autoplay-interval`. `mode`/`animation` are omitted when unspecified (WA supplies its own defaults).
|
|
19
|
+
- **Runs last in the pipeline** (after `TreeTransformer`): its options routinely wrap already-transformed components (callouts/badges/cards), and dialog/details/popover/tooltip must consume their own `>>>` upstream before our `^>>>$` split runs. Consequence: a `......` block is the outermost container and cannot be nested inside another container body (the same constraint `TreeTransformer` documents).
|
|
20
|
+
- **Plain-markdown degradation** (`render_as_markdown`, used for `.md` endpoints / llms.txt): the block degrades to its option bodies joined by blank lines, with the fences, params, and `>>>` separators dropped.
|
|
21
|
+
- New `TreeTransformer` producing Web Awesome's `<wa-tree>` / `<wa-tree-item>` from a **nested Markdown bullet list** — the first transformer that maps indentation (rather than flat item fences) onto a component. Ideal for file/directory layouts, taxonomies, and nested navigation.
|
|
22
|
+
- **Static-only scope**: Web Awesome's tree is fundamentally a *selection* control, and selection is interactive (needs JS). We deliberately emit a **display/navigation-only** tree — visual hierarchy via nesting, initial expand state, and leading folder/file icons, all declarative and static-safe. `selection`, `lazy`, `selected`, and selection events are skipped entirely.
|
|
23
|
+
- **Primary syntax**: a single `||||||` (6 pipes) open fence wrapping a normal nested Markdown list, closed by `||||||` (modeled on `LayoutTransformer`'s single-fence shape, not accordion's container+item fences). `|` is unused by any other transformer, and the transform runs before Markdown so there is no table collision. **Block alternative**: `:::wa-tree … :::`.
|
|
24
|
+
- **Fence token**: `open` (alias `expanded`) marks every branch node `expanded`. **Web Awesome runtime caveat** (verified against the WA 3.9.0 kit): `<wa-tree-item>` only honors a static `expanded` on items that are *visible at load*, so in practice `open` expands the **top-level** branches and deeper branches stay collapsed until their parent is opened (WA strips `expanded` from nested items at init). The attribute is still emitted on every branch on purpose — it's harmless (WA ignores the nested ones), records authorial intent, and is forward-compatible if WA ever honors nested initial-expand.
|
|
25
|
+
- **Per-node leading tokens** on each list item (stripped from the label, like the accordion item flags): `expanded` (force one branch open — subject to the same top-level-only WA caveat above) and `icon:name` (a leading content `<wa-icon name="name">` with no `slot`, e.g. `icon:folder`). The remaining text is the label.
|
|
26
|
+
- **Indentation parser**: list lines (`-`/`*`/`+`) are kept and their leading-whitespace width measured (a tab counts as four columns); nesting is built by comparing actual indent values, so 2-space and 4-space lists both work as long as children are strictly more indented than parents. Blank and non-list lines are skipped.
|
|
27
|
+
- **Labels are plain text** (HTML-escaped), so colon-bearing labels like `cbc:ID` and `<`/`>` are safe. `expanded` is emitted only on nodes that **have children** AND (the fence is `open` OR the node carries its own `expanded` flag); leaves never get `expanded`. Runs last in the pipeline (after accordion).
|
|
28
|
+
- **Plain-markdown degradation** (`render_as_markdown`, used for `.md` endpoints / llms.txt): the tree degrades to a clean nested bullet list (2-space indent per depth, tokens and fence stripped).
|
|
29
|
+
- Inline markdown / links in labels are a documented v1 follow-up; nesting a tree inside a markdown-converted body (accordion item, card) is not supported in v1 — the same pipeline constraint other components already have. Deep expand-on-load (beyond the top level) needs Web Awesome's interactive JS, so it is out of scope for the static surface.
|
|
30
|
+
|
|
31
|
+
### Documentation
|
|
32
|
+
|
|
33
|
+
- Documented the `<wa-tag with-remove>` static-site caveat in the README: the attribute renders a remove (×) button, but Web Awesome only *fires* a `wa-remove` event and does not remove the tag itself, so on a page with no authored JavaScript the button is inert. We **keep** the attribute (the emitted markup is valid Web Awesome) and document the one-line listener needed to make it functional, rather than dropping it from the static-safe surface. This also makes the existing 0.17.0 reference to "the `<wa-tag with-remove>` caveat" accurate.
|
|
34
|
+
|
|
35
|
+
## [0.17.0] - 2026-06-26
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
|
|
39
|
+
- New `VideoTransformer` producing Web Awesome's two media components — `<wa-video>` (a single embedded video with custom controls) and `<wa-video-playlist>` (a playlist wrapping multiple `<wa-video>` children). Both are Web Awesome **Pro** (experimental); the markup emitted is declarative and static-site-safe.
|
|
40
|
+
- **Single video** (primary): a `;;;<tokens>` fence, body, closing `;;;`. **Playlist** (primary): a `;;;;;;<tokens>` container wrapping bare `;;;` items (mirroring the carousel `~~~`/`~~~~~~` structure — the bare `;;;` item open keeps the closing `;;;;;;` from being mis-read as an item). Block alternatives: `:::wa-video <tokens>` and `:::wa-video-playlist <tokens>`. Runs in the pipeline immediately after `ComparisonTransformer`.
|
|
41
|
+
- **Body**: the first markdown link `[text](url)` supplies `title`/`src`; the first markdown image `` supplies `poster` (a negative lookbehind keeps the image's `[…]()` from being taken as the link). A block with no link (no `src`) is left untransformed.
|
|
42
|
+
- **Tokens**: `controls:none|standard|full` and `preload:auto|metadata|none` (enum-validated `key:value`; invalid values dropped) plus the boolean flags `autoplay`, `autoplay-muted`, `autoplay-on-visible`, `loop`, `muted` (whole-token matched, so `autoplay-muted` never triggers `autoplay`). The playlist's `controls` preset is forwarded to the container only — children omit it. Deterministic emission order: `src`, `poster`, `title`, `controls`, `preload`, then `autoplay`, `autoplay-muted`, `autoplay-on-visible`, `loop`, `muted`; `src`/`poster`/`title` are HTML-escaped.
|
|
43
|
+
- **Plain-markdown degradation** (`render_as_markdown`, used for `.md` endpoints / llms.txt): a single video degrades to `[title](src)`; a playlist degrades to a bulleted list of `- [title](src)`.
|
|
44
|
+
- Captions (`<track>`) and multi-format `<source>` children are documented v1 follow-ups — a single `src` attribute suffices today.
|
|
45
|
+
- New `DateTransformer` producing Web Awesome's two declarative timestamp components — `<wa-format-date>` (an absolute, locale-formatted date such as "June 26, 2026") and `<wa-relative-time>` ("3 days ago", optionally live-ticking). The date value is baked into the markup at build time; both components are pure declarative wrappers over the browser's `Intl.DateTimeFormat` / `Intl.RelativeTimeFormat`, with no data fetching — ideal for blog post dates, changelog stamps, and "last updated".
|
|
46
|
+
- **Inline syntax** (primary): `[[[ <date> <tokens> ]]]` — triple square brackets, single-line, transformed before Kramdown (runs right after `TooltipTransformer`). `[[[` collides with no other delimiter and survives Kramdown + Jekyll/Liquid.
|
|
47
|
+
- **Block alternative**: `:::wa-format-date <date> <tokens>` / `:::wa-relative-time <date> <tokens>` with an empty body closed by `:::`. The selector name chooses the mode directly.
|
|
48
|
+
- **Mode**: absolute (`<wa-format-date>`) is the default; a bare `relative` token in the inline form switches to `<wa-relative-time>`.
|
|
49
|
+
- **Date token**: the token matching ISO 8601 `YYYY-MM-DD` (optionally `THH:MM[:SS][.s][Z|±HH:MM]`) is passed verbatim (escaped) into `date="…"`. If omitted, `date` is dropped and the component shows the viewer's **current** time (runtime-now). Datetimes use the `T` separator (a space would break tokenization).
|
|
50
|
+
- **format-date formatting**: `style:short|medium|long|full` and `time:short|medium|long|full` presets expand to Web Awesome's granular attributes, with granular overrides (`weekday`, `era`, `year`, `month`, `day`, `hour`, `minute`, `second`, `hour-format`, `time-zone-name`, `time-zone`, `lang`/`locale` → `lang`) winning per key (rightmost-wins). Enum values are validated; invalid values and unknown tokens are silently dropped. A bare date with no style/time/granular field defaults to `style:long`. Deterministic emission order: `date weekday era year month day hour minute second time-zone-name time-zone hour-format lang`.
|
|
51
|
+
- **relative-time formatting**: `format` (`long|short|narrow`, default `long` omitted), `numeric` (`auto|always`, default `auto` omitted), `sync` (boolean live-update flag), and `lang`/`locale` → `lang`. Date/style tokens are ignored in relative mode. Deterministic emission order: `date format numeric sync lang`.
|
|
52
|
+
- **Plain-markdown degradation** (`render_as_markdown`, used for `.md` endpoints / llms.txt): each timestamp degrades to its raw date string (empty for a runtime-now timestamp), since plain text has no locale formatting.
|
|
53
|
+
- **Static-site caveat**: like `<wa-icon>`, both timestamp components render generated text into shadow DOM with no light-DOM fallback — with Web Awesome's JS disabled they show nothing. This matches our existing generated-content model (documented alongside the `<wa-tag with-remove>` caveat); no fallback text is emitted.
|
|
54
|
+
- `PopoverTransformer` and `TooltipTransformer` now accept **all twelve** Web Awesome placements — the four primary (`top`, `bottom`, `left`, `right`) plus the eight aligned variants (`top-start`, `top-end`, `right-start`, `right-end`, `bottom-start`, `bottom-end`, `left-start`, `left-end`) — matching `<wa-popover>`/`<wa-tooltip>`'s full `placement` surface. `AttributeParser` matches whole tokens, so `bottom-start` resolves without colliding with `bottom`.
|
|
55
|
+
- `PopoverTransformer` and `TooltipTransformer` gain a `skidding:N` token, mirroring `distance:N`. It emits `<wa-popover>`/`<wa-tooltip>`'s `skidding` attribute — the offset **along** the target (whereas `distance` is the offset **away** from it). Negative values are allowed (`skidding:-4`). Emission order is deterministic: `placement`, `without-arrow`, `distance`, `skidding` (popover) and `placement`, `distance`, `skidding` (tooltip).
|
|
56
|
+
- `TabsTransformer` supports a per-tab `disabled` flag as a **leading token** on the `+++ ` item header (e.g. `+++ disabled Coming soon`), mirroring the accordion item flags. It emits `<wa-tab disabled>` (the tab renders but cannot be selected) and strips the flag from the label; a non-leading occurrence of the word is left untouched. The `render_as_markdown` degradation strips the flag too (`### Coming soon`). Non-disabled tabs are byte-identical to before.
|
|
57
|
+
|
|
7
58
|
## [0.16.0] - 2026-06-25
|
|
8
59
|
|
|
9
60
|
### Added
|
data/README.md
CHANGED
|
@@ -29,6 +29,13 @@ Used as the transformation engine for the [jekyll-webawesome](https://github.com
|
|
|
29
29
|
| **Tab Group** | `++++++` | `:::wa-tabs` | `<wa-tab-group><wa-tab>content</wa-tab></wa-tab-group>` |
|
|
30
30
|
| **Tag** | `@@@brand` | `:::wa-tag brand` | `<wa-tag variant="brand">content</wa-tag>` |
|
|
31
31
|
|
|
32
|
+
> **Note on `<wa-tag>` `with-remove`:** the `with-remove` attribute renders a
|
|
33
|
+
> remove (×) button, but Web Awesome only *fires* a `wa-remove` event — it does
|
|
34
|
+
> not remove the tag for you. On a page with no JavaScript beyond the Web Awesome
|
|
35
|
+
> library, the button is inert. To make it functional, add your own `wa-remove`
|
|
36
|
+
> listener (e.g. a single global handler that removes `event.target`). The markup
|
|
37
|
+
> we emit is valid either way.
|
|
38
|
+
|
|
32
39
|
## Layout Utilities
|
|
33
40
|
|
|
34
41
|
Layout utilities use `::::` (quadruple colon) syntax to wrap content in CSS layout containers. Inner content is not markdown-converted, so component `:::` syntax inside layouts works normally.
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Markawesome
|
|
4
|
-
# Shared <wa-icon> attribute vocabulary (family/variant/animation) and emission helper.
|
|
5
|
-
# Values verified against Web Awesome 3.
|
|
4
|
+
# Shared <wa-icon> attribute vocabulary (family/variant/animation/canvas) and emission helper.
|
|
5
|
+
# Values verified against Web Awesome 3.10.0. Adding a value later is a one-line change.
|
|
6
6
|
module IconAttributes
|
|
7
7
|
SCHEMA = {
|
|
8
|
-
family: %w[
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
family: %w[
|
|
9
|
+
classic sharp duotone sharp-duotone brands
|
|
10
|
+
mosaic pixel vellum slab-duo slab-press-duo chisel etch graphite
|
|
11
|
+
jelly jelly-duo jelly-fill notdog notdog-duo slab slab-press
|
|
12
|
+
thumbprint utility utility-duo utility-fill whiteboard
|
|
13
|
+
],
|
|
14
|
+
variant: %w[thin light regular solid semibold],
|
|
15
|
+
animation: %w[
|
|
16
|
+
beat fade beat-fade bounce flip shake spin spin-pulse spin-reverse
|
|
17
|
+
flip-360 spin-snap spin-snap-4 spin-snap-8 buzz float jello swing wag
|
|
18
|
+
],
|
|
19
|
+
canvas: %w[fixed auto square roomy]
|
|
11
20
|
}.freeze
|
|
12
21
|
|
|
13
|
-
# Returns ordered ['family="…"', 'variant="…"', 'animation="…"'] for present
|
|
22
|
+
# Returns ordered ['family="…"', 'variant="…"', 'animation="…"', 'canvas="…"'] for present
|
|
23
|
+
# keys. Emission order is fixed (canvas last) for byte-for-byte parity with markawesome-js.
|
|
14
24
|
def self.pairs(attributes)
|
|
15
|
-
%i[family variant animation].filter_map do |key|
|
|
25
|
+
%i[family variant animation canvas].filter_map do |key|
|
|
16
26
|
"#{key}=\"#{attributes[key]}\"" if attributes[key]
|
|
17
27
|
end
|
|
18
28
|
end
|
|
@@ -26,7 +26,8 @@ module Markawesome
|
|
|
26
26
|
#
|
|
27
27
|
# @param component [Symbol] one of :accordion, :callout, :badge, :button,
|
|
28
28
|
# :card, :carousel, :comparison, :copy_button, :details, :dialog, :icon,
|
|
29
|
-
# :image_dialog, :layout, :popover, :tabs, :tag,
|
|
29
|
+
# :image_dialog, :layout, :popover, :random_content, :tabs, :tag,
|
|
30
|
+
# :tooltip.
|
|
30
31
|
# @yield [content, options] Proc that receives the full source content
|
|
31
32
|
# and the renderer options; returns the content with that component
|
|
32
33
|
# syntax replaced.
|
|
@@ -46,12 +47,14 @@ module Markawesome
|
|
|
46
47
|
layout
|
|
47
48
|
popover
|
|
48
49
|
tooltip
|
|
50
|
+
date
|
|
49
51
|
badge
|
|
50
52
|
button
|
|
51
53
|
callout
|
|
52
54
|
card
|
|
53
55
|
carousel
|
|
54
56
|
comparison
|
|
57
|
+
video
|
|
55
58
|
copy_button
|
|
56
59
|
details
|
|
57
60
|
image_dialog
|
|
@@ -60,18 +63,22 @@ module Markawesome
|
|
|
60
63
|
tag
|
|
61
64
|
tabs
|
|
62
65
|
accordion
|
|
66
|
+
tree
|
|
67
|
+
random_content
|
|
63
68
|
].freeze
|
|
64
69
|
|
|
65
70
|
TRANSFORMER_MAP = {
|
|
66
71
|
layout: LayoutTransformer,
|
|
67
72
|
popover: PopoverTransformer,
|
|
68
73
|
tooltip: TooltipTransformer,
|
|
74
|
+
date: DateTransformer,
|
|
69
75
|
badge: BadgeTransformer,
|
|
70
76
|
button: ButtonTransformer,
|
|
71
77
|
callout: CalloutTransformer,
|
|
72
78
|
card: CardTransformer,
|
|
73
79
|
carousel: CarouselTransformer,
|
|
74
80
|
comparison: ComparisonTransformer,
|
|
81
|
+
video: VideoTransformer,
|
|
75
82
|
copy_button: CopyButtonTransformer,
|
|
76
83
|
details: DetailsTransformer,
|
|
77
84
|
image_dialog: ImageDialogTransformer,
|
|
@@ -79,7 +86,9 @@ module Markawesome
|
|
|
79
86
|
icon: IconTransformer,
|
|
80
87
|
tag: TagTransformer,
|
|
81
88
|
tabs: TabsTransformer,
|
|
82
|
-
accordion: AccordionTransformer
|
|
89
|
+
accordion: AccordionTransformer,
|
|
90
|
+
tree: TreeTransformer,
|
|
91
|
+
random_content: RandomContentTransformer
|
|
83
92
|
}.freeze
|
|
84
93
|
|
|
85
94
|
def self.process(content, options = {})
|
|
@@ -13,12 +13,14 @@ module Markawesome
|
|
|
13
13
|
content = LayoutTransformer.transform(content)
|
|
14
14
|
content = PopoverTransformer.transform(content)
|
|
15
15
|
content = TooltipTransformer.transform(content)
|
|
16
|
+
content = DateTransformer.transform(content)
|
|
16
17
|
content = BadgeTransformer.transform(content)
|
|
17
18
|
content = ButtonTransformer.transform(content)
|
|
18
19
|
content = CalloutTransformer.transform(content)
|
|
19
20
|
content = CardTransformer.transform(content)
|
|
20
21
|
content = CarouselTransformer.transform(content)
|
|
21
22
|
content = ComparisonTransformer.transform(content)
|
|
23
|
+
content = VideoTransformer.transform(content)
|
|
22
24
|
content = CopyButtonTransformer.transform(content)
|
|
23
25
|
content = DetailsTransformer.transform(content)
|
|
24
26
|
|
|
@@ -37,6 +39,17 @@ module Markawesome
|
|
|
37
39
|
# components (same reason tabs runs near the end).
|
|
38
40
|
content = AccordionTransformer.transform(content)
|
|
39
41
|
|
|
42
|
+
# Tree runs after accordion; its body is a plain nested list (never a
|
|
43
|
+
# markdown-converted body), so ordering relative to accordion is moot.
|
|
44
|
+
content = TreeTransformer.transform(content)
|
|
45
|
+
|
|
46
|
+
# Random-content runs LAST: its options routinely wrap already-transformed
|
|
47
|
+
# components (callouts/badges/cards), and dialog/details/popover/tooltip
|
|
48
|
+
# must consume their own `>>>` upstream before our `^>>>$` item split
|
|
49
|
+
# runs. Consequence: a `......` block is the outermost container and cannot
|
|
50
|
+
# be nested inside another container body (same constraint Tree documents).
|
|
51
|
+
content = RandomContentTransformer.transform(content)
|
|
52
|
+
|
|
40
53
|
CodeBlockProtector.restore(content, tokens)
|
|
41
54
|
end
|
|
42
55
|
end
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_transformer'
|
|
4
|
+
|
|
5
|
+
module Markawesome
|
|
6
|
+
# Transforms declarative timestamp syntax into Web Awesome's two timestamp
|
|
7
|
+
# components:
|
|
8
|
+
# <wa-format-date> — an absolute, locale-formatted date ("June 26, 2026")
|
|
9
|
+
# <wa-relative-time> — a relative phrase ("3 days ago"), optionally ticking
|
|
10
|
+
#
|
|
11
|
+
# These are pure declarative wrappers over the browser's Intl.DateTimeFormat /
|
|
12
|
+
# Intl.RelativeTimeFormat: the date value is baked into the markup at build
|
|
13
|
+
# time, with no data fetching. Great for blog dates, changelog stamps, and
|
|
14
|
+
# "last updated".
|
|
15
|
+
#
|
|
16
|
+
# Inline (primary): [[[ <date> <tokens> ]]]
|
|
17
|
+
# Block (alternative): :::wa-format-date <date> <tokens> / :::wa-relative-time …
|
|
18
|
+
# followed by a closing ::: (empty body)
|
|
19
|
+
#
|
|
20
|
+
# Mode: absolute (<wa-format-date>) is the default; a bare `relative` token in
|
|
21
|
+
# the inline form switches to <wa-relative-time>. The block selector name
|
|
22
|
+
# chooses the mode directly.
|
|
23
|
+
#
|
|
24
|
+
# Static-site caveat: both components render generated text into shadow DOM
|
|
25
|
+
# with no light-DOM fallback — with Web Awesome's JS disabled they show
|
|
26
|
+
# nothing. This is identical to <wa-icon> and the other generated-content
|
|
27
|
+
# components we already emit, so it is consistent with our model.
|
|
28
|
+
class DateTransformer < BaseTransformer
|
|
29
|
+
# Inline: content excludes `]`, non-greedy, multiple-per-line, single-line.
|
|
30
|
+
INLINE_REGEX = /\[\[\[[ \t]*([^\]\r\n]+?)[ \t]*\]\]\]/
|
|
31
|
+
# Block: selector name picks the mode; an empty body, closed by `:::`.
|
|
32
|
+
ALTERNATIVE_REGEX = /^:::wa-(format-date|relative-time)[ \t]*([^\n]*)\n:::$/
|
|
33
|
+
|
|
34
|
+
# A token is the date when it is an ISO 8601 date or datetime (datetimes use
|
|
35
|
+
# the `T` separator — a space would break whitespace tokenization).
|
|
36
|
+
DATE_TOKEN_REGEX =
|
|
37
|
+
/\A\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)?\z/
|
|
38
|
+
|
|
39
|
+
# style:/time: presets expand to Web Awesome's granular date/time attributes.
|
|
40
|
+
STYLE_PRESETS = {
|
|
41
|
+
'short' => { 'month' => 'numeric', 'day' => 'numeric', 'year' => '2-digit' },
|
|
42
|
+
'medium' => { 'month' => 'short', 'day' => 'numeric', 'year' => 'numeric' },
|
|
43
|
+
'long' => { 'month' => 'long', 'day' => 'numeric', 'year' => 'numeric' },
|
|
44
|
+
'full' => { 'weekday' => 'long', 'month' => 'long', 'day' => 'numeric', 'year' => 'numeric' }
|
|
45
|
+
}.freeze
|
|
46
|
+
|
|
47
|
+
TIME_PRESETS = {
|
|
48
|
+
'short' => { 'hour' => 'numeric', 'minute' => 'numeric' },
|
|
49
|
+
'medium' => { 'hour' => 'numeric', 'minute' => 'numeric', 'second' => 'numeric' },
|
|
50
|
+
'long' => { 'hour' => 'numeric', 'minute' => 'numeric', 'second' => 'numeric', 'time-zone-name' => 'short' },
|
|
51
|
+
'full' => { 'hour' => 'numeric', 'minute' => 'numeric', 'second' => 'numeric', 'time-zone-name' => 'long' }
|
|
52
|
+
}.freeze
|
|
53
|
+
|
|
54
|
+
# Granular key:value tokens that pass through to the same-named WA attribute,
|
|
55
|
+
# validated against an allowed enum (invalid values dropped).
|
|
56
|
+
GRANULAR_ENUMS = {
|
|
57
|
+
'weekday' => %w[narrow short long],
|
|
58
|
+
'era' => %w[narrow short long],
|
|
59
|
+
'year' => %w[numeric 2-digit],
|
|
60
|
+
'month' => %w[numeric 2-digit narrow short long],
|
|
61
|
+
'day' => %w[numeric 2-digit],
|
|
62
|
+
'hour' => %w[numeric 2-digit],
|
|
63
|
+
'minute' => %w[numeric 2-digit],
|
|
64
|
+
'second' => %w[numeric 2-digit],
|
|
65
|
+
'hour-format' => %w[auto 12 24],
|
|
66
|
+
'time-zone-name' => %w[short long]
|
|
67
|
+
}.freeze
|
|
68
|
+
|
|
69
|
+
# Granular keys that count as an explicit date/time field — their presence
|
|
70
|
+
# (or a style:/time: preset) suppresses the style:long default.
|
|
71
|
+
CONTENT_FIELDS = %w[weekday era year month day hour minute second time-zone-name].freeze
|
|
72
|
+
|
|
73
|
+
# Deterministic emission order (required for byte-for-byte parity).
|
|
74
|
+
FORMAT_DATE_ORDER = %w[date weekday era year month day hour minute second
|
|
75
|
+
time-zone-name time-zone hour-format lang].freeze
|
|
76
|
+
|
|
77
|
+
RELATIVE_FORMATS = %w[long short narrow].freeze
|
|
78
|
+
RELATIVE_NUMERICS = %w[auto always].freeze
|
|
79
|
+
|
|
80
|
+
def self.transform(content)
|
|
81
|
+
patterns = [
|
|
82
|
+
{ regex: INLINE_REGEX, block: proc { |_m, md| render_tokens(md[1], nil) } },
|
|
83
|
+
{ regex: ALTERNATIVE_REGEX,
|
|
84
|
+
block: proc { |_m, md| render_tokens(md[2], md[1] == 'relative-time' ? :relative : :absolute) } }
|
|
85
|
+
]
|
|
86
|
+
apply_multiple_patterns(content, patterns)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Plain-markdown degradation: there is no locale formatting in plain text,
|
|
90
|
+
# so each timestamp degrades to its raw date string (empty when omitted).
|
|
91
|
+
def self.render_as_markdown(content, _options = {})
|
|
92
|
+
patterns = [
|
|
93
|
+
{ regex: INLINE_REGEX, block: proc { |_m, md| extract_date(md[1]) } },
|
|
94
|
+
{ regex: ALTERNATIVE_REGEX, block: proc { |_m, md| extract_date(md[2]) } }
|
|
95
|
+
]
|
|
96
|
+
apply_multiple_patterns(content, patterns)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
class << self
|
|
100
|
+
private
|
|
101
|
+
|
|
102
|
+
def render_tokens(token_string, mode_override)
|
|
103
|
+
tokens = token_string.to_s.strip.split(/\s+/)
|
|
104
|
+
date, tokens = split_date(tokens)
|
|
105
|
+
mode = mode_override || (tokens.include?('relative') ? :relative : :absolute)
|
|
106
|
+
|
|
107
|
+
mode == :relative ? build_relative_time(date, tokens) : build_format_date(date, tokens)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Pull the first date/datetime token out, leaving the option tokens.
|
|
111
|
+
def split_date(tokens)
|
|
112
|
+
index = tokens.index { |token| token.match?(DATE_TOKEN_REGEX) }
|
|
113
|
+
return [nil, tokens] unless index
|
|
114
|
+
|
|
115
|
+
[tokens[index], tokens[0...index] + tokens[(index + 1)..]]
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def extract_date(token_string)
|
|
119
|
+
tokens = token_string.to_s.strip.split(/\s+/)
|
|
120
|
+
tokens.find { |token| token.match?(DATE_TOKEN_REGEX) }.to_s
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def build_format_date(date, tokens)
|
|
124
|
+
attrs = {}
|
|
125
|
+
apply_presets(tokens, attrs)
|
|
126
|
+
apply_granular(tokens, attrs)
|
|
127
|
+
# A bare date (no style/time/granular field) defaults to style:long.
|
|
128
|
+
attrs.merge!(STYLE_PRESETS['long']) if (attrs.keys & CONTENT_FIELDS).empty?
|
|
129
|
+
attrs['date'] = date if date
|
|
130
|
+
|
|
131
|
+
parts = FORMAT_DATE_ORDER.filter_map do |key|
|
|
132
|
+
"#{key}=\"#{escape_html(attrs[key])}\"" if attrs.key?(key)
|
|
133
|
+
end
|
|
134
|
+
build_element('wa-format-date', parts)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Apply the rightmost valid style: and time: presets.
|
|
138
|
+
def apply_presets(tokens, attrs)
|
|
139
|
+
style = nil
|
|
140
|
+
time = nil
|
|
141
|
+
tokens.each do |token|
|
|
142
|
+
if (m = token.match(/\Astyle:(.+)\z/)) && STYLE_PRESETS.key?(m[1])
|
|
143
|
+
style = m[1]
|
|
144
|
+
elsif (m = token.match(/\Atime:(.+)\z/)) && TIME_PRESETS.key?(m[1])
|
|
145
|
+
time = m[1]
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
attrs.merge!(STYLE_PRESETS[style]) if style
|
|
149
|
+
attrs.merge!(TIME_PRESETS[time]) if time
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Apply granular enum keys (override presets) and free-string modifiers
|
|
153
|
+
# (time-zone, lang/locale). Later tokens win.
|
|
154
|
+
def apply_granular(tokens, attrs)
|
|
155
|
+
tokens.each do |token|
|
|
156
|
+
next unless (m = token.match(/\A([a-z-]+):(.+)\z/))
|
|
157
|
+
|
|
158
|
+
key = m[1]
|
|
159
|
+
value = m[2]
|
|
160
|
+
if GRANULAR_ENUMS[key]&.include?(value)
|
|
161
|
+
attrs[key] = value
|
|
162
|
+
elsif key == 'time-zone'
|
|
163
|
+
attrs['time-zone'] = value
|
|
164
|
+
elsif %w[lang locale].include?(key)
|
|
165
|
+
attrs['lang'] = value
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def build_relative_time(date, tokens)
|
|
171
|
+
opts = parse_relative_options(tokens)
|
|
172
|
+
parts = []
|
|
173
|
+
parts << "date=\"#{escape_html(date)}\"" if date
|
|
174
|
+
parts << "format=\"#{opts[:format]}\"" if opts[:format] && opts[:format] != 'long'
|
|
175
|
+
parts << "numeric=\"#{opts[:numeric]}\"" if opts[:numeric] && opts[:numeric] != 'auto'
|
|
176
|
+
parts << 'sync' if opts[:sync]
|
|
177
|
+
parts << "lang=\"#{escape_html(opts[:lang])}\"" if opts[:lang]
|
|
178
|
+
build_element('wa-relative-time', parts)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def parse_relative_options(tokens)
|
|
182
|
+
opts = { format: nil, numeric: nil, sync: false, lang: nil }
|
|
183
|
+
tokens.each do |token|
|
|
184
|
+
if token == 'sync'
|
|
185
|
+
opts[:sync] = true
|
|
186
|
+
elsif (m = token.match(/\Aformat:(.+)\z/)) && RELATIVE_FORMATS.include?(m[1])
|
|
187
|
+
opts[:format] = m[1]
|
|
188
|
+
elsif (m = token.match(/\Anumeric:(.+)\z/)) && RELATIVE_NUMERICS.include?(m[1])
|
|
189
|
+
opts[:numeric] = m[1]
|
|
190
|
+
elsif (m = token.match(/\A(?:lang|locale):(.+)\z/))
|
|
191
|
+
opts[:lang] = m[1]
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
opts
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def build_element(tag, parts)
|
|
198
|
+
return "<#{tag}></#{tag}>" if parts.empty?
|
|
199
|
+
|
|
200
|
+
"<#{tag} #{parts.join(' ')}></#{tag}>"
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def escape_html(text)
|
|
204
|
+
text.gsub('&', '&').gsub('<', '<').gsub('>', '>')
|
|
205
|
+
.gsub('"', '"').gsub("'", ''')
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
@@ -7,13 +7,14 @@ require_relative '../icon_attributes'
|
|
|
7
7
|
module Markawesome
|
|
8
8
|
# Transforms icon syntax into wa-icon elements
|
|
9
9
|
# Primary syntax: $$$icon-name (name only, decorative)
|
|
10
|
-
# Alternative syntax: :::wa-icon icon-name [family] [variant] [animation]\n[label]\n:::
|
|
10
|
+
# Alternative syntax: :::wa-icon icon-name [family] [variant] [animation] [canvas]\n[label]\n:::
|
|
11
11
|
#
|
|
12
12
|
# Examples:
|
|
13
13
|
# $$$settings -> <wa-icon name="settings"></wa-icon>
|
|
14
14
|
# $$$home -> <wa-icon name="home"></wa-icon>
|
|
15
15
|
# $$$user-circle -> <wa-icon name="user-circle"></wa-icon>
|
|
16
16
|
# :::wa-icon star spin\n::: -> <wa-icon name="star" animation="spin"></wa-icon>
|
|
17
|
+
# :::wa-icon star roomy\n::: -> <wa-icon name="star" canvas="roomy"></wa-icon>
|
|
17
18
|
# :::wa-icon heart solid\nFavorite\n::: ->
|
|
18
19
|
# <wa-icon name="heart" variant="solid" label="Favorite"></wa-icon>
|
|
19
20
|
class IconTransformer < BaseTransformer
|
|
@@ -11,12 +11,15 @@ module Markawesome
|
|
|
11
11
|
# Inline syntax: &&¶ms? trigger text >>> popover content&&&
|
|
12
12
|
#
|
|
13
13
|
# Params: space-separated tokens (order doesn't matter)
|
|
14
|
-
# Placement: top (default), bottom, left, right
|
|
14
|
+
# Placement: top (default), bottom, left, right, plus the eight aligned
|
|
15
|
+
# variants (top-start, top-end, right-start, …) — the full wa-popover surface
|
|
15
16
|
# Flags: without-arrow
|
|
16
|
-
# Distance: distance:N (e.g., distance:10)
|
|
17
|
+
# Distance: distance:N (e.g., distance:10) — offset away from the target
|
|
18
|
+
# Skidding: skidding:N (e.g., skidding:12, skidding:-4) — offset along the target
|
|
17
19
|
class PopoverTransformer < BaseTransformer
|
|
18
20
|
POPOVER_ATTRIBUTES = {
|
|
19
|
-
placement: %w[top
|
|
21
|
+
placement: %w[top top-start top-end right right-start right-end
|
|
22
|
+
bottom bottom-start bottom-end left left-start left-end],
|
|
20
23
|
without_arrow: %w[without-arrow],
|
|
21
24
|
trigger_style: %w[link]
|
|
22
25
|
}.freeze
|
|
@@ -42,13 +45,13 @@ module Markawesome
|
|
|
42
45
|
popover_content = matchdata[2].strip
|
|
43
46
|
|
|
44
47
|
params_string, trigger_text = parse_inline_trigger_and_params(combined)
|
|
45
|
-
placement, without_arrow, distance, _link_style = parse_parameters(params_string)
|
|
48
|
+
placement, without_arrow, distance, _link_style, skidding = parse_parameters(params_string)
|
|
46
49
|
|
|
47
50
|
popover_id = generate_popover_id(trigger_text, popover_content, seen_ids)
|
|
48
51
|
|
|
49
52
|
build_inline_popover_html(popover_id, trigger_text, popover_content,
|
|
50
53
|
{ placement: placement, without_arrow: without_arrow,
|
|
51
|
-
distance: distance })
|
|
54
|
+
distance: distance, skidding: skidding })
|
|
52
55
|
end
|
|
53
56
|
}
|
|
54
57
|
|
|
@@ -57,7 +60,7 @@ module Markawesome
|
|
|
57
60
|
trigger_text = trigger_text.strip
|
|
58
61
|
popover_content = popover_content.strip
|
|
59
62
|
|
|
60
|
-
placement, without_arrow, distance, link_style = parse_parameters(params_string)
|
|
63
|
+
placement, without_arrow, distance, link_style, skidding = parse_parameters(params_string)
|
|
61
64
|
|
|
62
65
|
popover_id = generate_popover_id(trigger_text, popover_content, seen_ids)
|
|
63
66
|
|
|
@@ -65,7 +68,7 @@ module Markawesome
|
|
|
65
68
|
|
|
66
69
|
build_popover_html(popover_id, trigger_text, content_html,
|
|
67
70
|
{ placement: placement, without_arrow: without_arrow,
|
|
68
|
-
distance: distance, link_style: link_style })
|
|
71
|
+
distance: distance, link_style: link_style, skidding: skidding })
|
|
69
72
|
end
|
|
70
73
|
|
|
71
74
|
# Inline patterns first to avoid conflicts with block patterns
|
|
@@ -106,19 +109,21 @@ module Markawesome
|
|
|
106
109
|
private
|
|
107
110
|
|
|
108
111
|
def parse_parameters(params_string)
|
|
109
|
-
return ['top', false, nil, false] if params_string.nil? || params_string.strip.empty?
|
|
112
|
+
return ['top', false, nil, false, nil] if params_string.nil? || params_string.strip.empty?
|
|
110
113
|
|
|
111
114
|
attributes = AttributeParser.parse(params_string, POPOVER_ATTRIBUTES)
|
|
112
115
|
placement = attributes[:placement] || 'top'
|
|
113
116
|
without_arrow = attributes[:without_arrow] == 'without-arrow'
|
|
114
117
|
link_style = attributes[:trigger_style] == 'link'
|
|
115
118
|
|
|
116
|
-
# Look for distance:N
|
|
119
|
+
# Look for distance:N and skidding:N parameters (skidding may be negative)
|
|
117
120
|
tokens = params_string.strip.split(/\s+/)
|
|
118
121
|
distance_token = tokens.find { |token| token.match?(/^distance:\d+$/) }
|
|
119
122
|
distance = distance_token&.sub('distance:', '')
|
|
123
|
+
skidding_token = tokens.find { |token| token.match?(/^skidding:-?\d+$/) }
|
|
124
|
+
skidding = skidding_token&.sub('skidding:', '')
|
|
120
125
|
|
|
121
|
-
[placement, without_arrow, distance, link_style]
|
|
126
|
+
[placement, without_arrow, distance, link_style, skidding]
|
|
122
127
|
end
|
|
123
128
|
|
|
124
129
|
def generate_popover_id(trigger_text, content, seen_ids)
|
|
@@ -156,42 +161,36 @@ module Markawesome
|
|
|
156
161
|
|
|
157
162
|
def popover_param?(token)
|
|
158
163
|
POPOVER_ATTRIBUTES.any? { |_attr, values| values.include?(token) } ||
|
|
159
|
-
token.match?(/^distance:\d+$/)
|
|
164
|
+
token.match?(/^distance:\d+$/) ||
|
|
165
|
+
token.match?(/^skidding:-?\d+$/)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Build the <wa-popover> attribute list. Emission order is fixed:
|
|
169
|
+
# for, placement, without-arrow, distance, skidding.
|
|
170
|
+
def popover_attributes(popover_id, options)
|
|
171
|
+
attrs = ["for='#{popover_id}'", "placement='#{options[:placement]}'"]
|
|
172
|
+
attrs << 'without-arrow' if options[:without_arrow]
|
|
173
|
+
attrs << "distance='#{options[:distance]}'" if options[:distance]
|
|
174
|
+
attrs << "skidding='#{options[:skidding]}'" if options[:skidding]
|
|
175
|
+
attrs
|
|
160
176
|
end
|
|
161
177
|
|
|
162
178
|
def build_inline_popover_html(popover_id, trigger_text, content_text, options)
|
|
163
179
|
trigger_content = escape_html(trigger_text)
|
|
164
|
-
content_escaped = escape_html(content_text)
|
|
165
|
-
content_escaped = content_escaped.gsub('\n', '<br>')
|
|
166
|
-
|
|
167
|
-
popover_attrs = ["for='#{popover_id}'"]
|
|
168
|
-
popover_attrs << "placement='#{options[:placement]}'"
|
|
169
|
-
popover_attrs << 'without-arrow' if options[:without_arrow]
|
|
170
|
-
popover_attrs << "distance='#{options[:distance]}'" if options[:distance]
|
|
180
|
+
content_escaped = escape_html(content_text).gsub('\n', '<br>')
|
|
171
181
|
|
|
182
|
+
attrs = popover_attributes(popover_id, options)
|
|
172
183
|
trigger = build_trigger(popover_id, trigger_content, true)
|
|
173
184
|
|
|
174
|
-
"#{trigger}<wa-popover #{
|
|
185
|
+
"#{trigger}<wa-popover #{attrs.join(' ')}>#{content_escaped}</wa-popover>"
|
|
175
186
|
end
|
|
176
187
|
|
|
177
188
|
def build_popover_html(popover_id, trigger_text, content_html, options)
|
|
178
|
-
# Escape trigger text for security
|
|
179
189
|
trigger_content = escape_html(trigger_text)
|
|
180
|
-
|
|
181
|
-
# Build popover attributes
|
|
182
|
-
popover_attrs = ["for='#{popover_id}'"]
|
|
183
|
-
popover_attrs << "placement='#{options[:placement]}'"
|
|
184
|
-
popover_attrs << 'without-arrow' if options[:without_arrow]
|
|
185
|
-
popover_attrs << "distance='#{options[:distance]}'" if options[:distance]
|
|
186
|
-
|
|
190
|
+
attrs = popover_attributes(popover_id, options)
|
|
187
191
|
trigger = build_trigger(popover_id, trigger_content, options[:link_style])
|
|
188
192
|
|
|
189
|
-
|
|
190
|
-
html << trigger
|
|
191
|
-
html << "<wa-popover #{popover_attrs.join(' ')}>"
|
|
192
|
-
html << content_html
|
|
193
|
-
html << '</wa-popover>'
|
|
194
|
-
html.join("\n")
|
|
193
|
+
[trigger, "<wa-popover #{attrs.join(' ')}>", content_html, '</wa-popover>'].join("\n")
|
|
195
194
|
end
|
|
196
195
|
|
|
197
196
|
def build_trigger(popover_id, trigger_content, link_style)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_transformer'
|
|
4
|
+
require_relative '../attribute_parser'
|
|
5
|
+
|
|
6
|
+
module Markawesome
|
|
7
|
+
# Transforms random-content syntax into Web Awesome's experimental
|
|
8
|
+
# <wa-random-content> element, which shows one or more of its direct element
|
|
9
|
+
# children at random (optionally rotating them) and hides the rest — all in
|
|
10
|
+
# WA's own runtime, so the author writes zero JavaScript. Ideal for a "little
|
|
11
|
+
# bit dynamic" rotating tips / testimonials / featured-content block on an
|
|
12
|
+
# otherwise static site.
|
|
13
|
+
#
|
|
14
|
+
# Primary syntax:
|
|
15
|
+
# ......mode:random items:2 animation:fade
|
|
16
|
+
# First option
|
|
17
|
+
# >>>
|
|
18
|
+
# Second option
|
|
19
|
+
# ......
|
|
20
|
+
# Alternative syntax:
|
|
21
|
+
# :::wa-random-content <params>
|
|
22
|
+
# First option
|
|
23
|
+
# >>>
|
|
24
|
+
# Second option
|
|
25
|
+
# :::
|
|
26
|
+
#
|
|
27
|
+
# Each option (split on a `>>>` line) has its rendered Markdown wrapped in a
|
|
28
|
+
# single <div> so WA sees exactly one selectable element child per option.
|
|
29
|
+
#
|
|
30
|
+
# Params (order-independent, on the opening fence line):
|
|
31
|
+
# - mode: unique (WA default) | random | sequence — bare enum or mode:VALUE
|
|
32
|
+
# - animation: none | fade | fade-up | fade-down | fade-left | fade-right —
|
|
33
|
+
# bare enum or animation:VALUE
|
|
34
|
+
# - autoplay: bare boolean flag
|
|
35
|
+
# - items: a bare integer or items:N (how many children to show)
|
|
36
|
+
# - autoplay-interval:N (ms between rotations)
|
|
37
|
+
# Unknown/invalid tokens are silently ignored. Deterministic emission order:
|
|
38
|
+
# mode, items, animation, autoplay, autoplay-interval.
|
|
39
|
+
#
|
|
40
|
+
# The `>>>` separator is the SHARED glyph already used inside
|
|
41
|
+
# details/dialog/popover/tooltip; it only acts as an item separator *inside* a
|
|
42
|
+
# `......`/`:::wa-random-content` block. A line of exactly `>>>` or `......`
|
|
43
|
+
# inside an option is therefore a separator/close-fence — options cannot
|
|
44
|
+
# contain those literal lines (a hard constraint, like carousel's `~~~`).
|
|
45
|
+
class RandomContentTransformer < BaseTransformer
|
|
46
|
+
COMPONENT_ATTRIBUTES = {
|
|
47
|
+
mode: %w[unique random sequence],
|
|
48
|
+
animation: %w[none fade fade-up fade-down fade-left fade-right],
|
|
49
|
+
autoplay: %w[autoplay]
|
|
50
|
+
}.freeze
|
|
51
|
+
|
|
52
|
+
# Dots MUST be escaped. The body is unstructured `(.*?)` under /m, so the
|
|
53
|
+
# closing anchor makes an unclosed fence not match and lets multiple blocks
|
|
54
|
+
# match left-to-right. Deliberately NO `\s*` after the alt fence (unlike
|
|
55
|
+
# carousel): with an unstructured body a greedy `\s*` would swallow the
|
|
56
|
+
# first newline and capture the first option line as params. `([^\n]*)`
|
|
57
|
+
# only — a leading space on the alt form is stripped by the parser.
|
|
58
|
+
PRIMARY_REGEX = /^\.{6}([^\n]*)\n(.*?)\n\.{6}/m
|
|
59
|
+
ALTERNATIVE_REGEX = /^:::wa-random-content([^\n]*)\n(.*?)\n:::/m
|
|
60
|
+
ITEM_SEPARATOR = /^>>>$/
|
|
61
|
+
|
|
62
|
+
def self.transform(content)
|
|
63
|
+
transform_proc = proc do |params, items_block|
|
|
64
|
+
build_html(extract_items(items_block), parse_params(params))
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
patterns = dual_syntax_patterns(PRIMARY_REGEX, ALTERNATIVE_REGEX, transform_proc)
|
|
68
|
+
apply_multiple_patterns(content, patterns)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Degrade to the option bodies joined by blank lines (fences, params, and
|
|
72
|
+
# `>>>` separators dropped), used for `.md` endpoints / llms.txt.
|
|
73
|
+
def self.render_as_markdown(content, _options = {})
|
|
74
|
+
transform_proc = proc do |_params, items_block|
|
|
75
|
+
extract_items(items_block).reject(&:empty?).join("\n\n")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
patterns = dual_syntax_patterns(PRIMARY_REGEX, ALTERNATIVE_REGEX, transform_proc)
|
|
79
|
+
apply_multiple_patterns(content, patterns)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class << self
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def extract_items(items_block)
|
|
86
|
+
items_block.split(ITEM_SEPARATOR).map(&:strip)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def parse_params(params)
|
|
90
|
+
return {} if params.nil? || params.strip.empty?
|
|
91
|
+
|
|
92
|
+
result = {}
|
|
93
|
+
|
|
94
|
+
# Bare enum/boolean tokens via AttributeParser (rightmost-wins).
|
|
95
|
+
attributes = AttributeParser.parse(params, COMPONENT_ATTRIBUTES)
|
|
96
|
+
result['mode'] = attributes[:mode] if attributes[:mode]
|
|
97
|
+
result['animation'] = attributes[:animation] if attributes[:animation]
|
|
98
|
+
result['autoplay'] = true if attributes[:autoplay]
|
|
99
|
+
|
|
100
|
+
# Manual pass for key:value and bare-integer tokens.
|
|
101
|
+
params.strip.split(/\s+/).each { |token| merge_manual_token(result, token) }
|
|
102
|
+
|
|
103
|
+
result
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Fold a single space-separated token into the parsed attribute hash:
|
|
107
|
+
# `mode:`/`animation:` (enum-validated), `items:` / bare integer, and
|
|
108
|
+
# `autoplay-interval:`. Anything else is ignored.
|
|
109
|
+
def merge_manual_token(result, token)
|
|
110
|
+
if token.include?(':')
|
|
111
|
+
key, value = token.split(':', 2)
|
|
112
|
+
case key
|
|
113
|
+
when 'mode'
|
|
114
|
+
result['mode'] = value if COMPONENT_ATTRIBUTES[:mode].include?(value)
|
|
115
|
+
when 'animation'
|
|
116
|
+
result['animation'] = value if COMPONENT_ATTRIBUTES[:animation].include?(value)
|
|
117
|
+
when 'items'
|
|
118
|
+
result['items'] = value
|
|
119
|
+
when 'autoplay-interval'
|
|
120
|
+
result['autoplay-interval'] = value
|
|
121
|
+
end
|
|
122
|
+
elsif token.match?(/^\d+$/)
|
|
123
|
+
result['items'] = token
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def build_html(items, params)
|
|
128
|
+
attr_string = build_attributes(params)
|
|
129
|
+
|
|
130
|
+
# Empty options are dropped — an empty rotating option would show
|
|
131
|
+
# nothing. Keep Kramdown's trailing "\n" inside each <div> (no strip).
|
|
132
|
+
divs = items.reject(&:empty?).map { |item| "<div>#{markdown_to_html(item)}</div>" }.join
|
|
133
|
+
|
|
134
|
+
"<wa-random-content#{attr_string}>#{divs}</wa-random-content>"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Fixed emission order for byte-parity: mode, items, animation, autoplay,
|
|
138
|
+
# autoplay-interval.
|
|
139
|
+
def build_attributes(params)
|
|
140
|
+
attrs = []
|
|
141
|
+
attrs << "mode=\"#{params['mode']}\"" if params['mode']
|
|
142
|
+
attrs << "items=\"#{params['items']}\"" if params['items']
|
|
143
|
+
attrs << "animation=\"#{params['animation']}\"" if params['animation']
|
|
144
|
+
attrs << 'autoplay' if params['autoplay']
|
|
145
|
+
attrs << "autoplay-interval=\"#{params['autoplay-interval']}\"" if params['autoplay-interval']
|
|
146
|
+
|
|
147
|
+
attrs.empty? ? '' : " #{attrs.join(' ')}"
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -12,6 +12,8 @@ module Markawesome
|
|
|
12
12
|
# - activation: auto (default), manual
|
|
13
13
|
# - active: panel name to show initially (e.g., "general", "tab-2")
|
|
14
14
|
# - no-scroll-controls: disables scroll arrows
|
|
15
|
+
# Per-tab flag (leading token on the `+++ ` item header, mirroring accordion):
|
|
16
|
+
# - disabled: this tab renders but cannot be selected (e.g., "+++ disabled Coming soon")
|
|
15
17
|
class TabsTransformer < BaseTransformer
|
|
16
18
|
COMPONENT_ATTRIBUTES = {
|
|
17
19
|
placement: %w[top bottom start end],
|
|
@@ -66,7 +68,8 @@ module Markawesome
|
|
|
66
68
|
transform_proc = proc do |_params_string, tabs_block, _third|
|
|
67
69
|
tab_contents = tabs_block.scan(/^\+\+\+ ([^\n]+)\n(.*?)\n\+\+\+/m)
|
|
68
70
|
tab_contents.map do |title, panel_content|
|
|
69
|
-
|
|
71
|
+
label, = parse_tab_header(title)
|
|
72
|
+
"### #{label}\n\n#{panel_content.strip}"
|
|
70
73
|
end.join("\n\n")
|
|
71
74
|
end
|
|
72
75
|
|
|
@@ -85,7 +88,11 @@ module Markawesome
|
|
|
85
88
|
|
|
86
89
|
tab_contents.each_with_index do |(title, panel_content), index|
|
|
87
90
|
tab_id = "tab-#{index + 1}"
|
|
88
|
-
|
|
91
|
+
label, disabled = parse_tab_header(title)
|
|
92
|
+
|
|
93
|
+
tab_attrs = ["panel=\"#{tab_id}\""]
|
|
94
|
+
tab_attrs << 'disabled' if disabled
|
|
95
|
+
tabs << "<wa-tab #{tab_attrs.join(' ')}>#{label}</wa-tab>"
|
|
89
96
|
|
|
90
97
|
panel_html = markdown_to_html(panel_content.strip)
|
|
91
98
|
tab_panels << "<wa-tab-panel name=\"#{tab_id}\">#{panel_html}</wa-tab-panel>"
|
|
@@ -93,6 +100,17 @@ module Markawesome
|
|
|
93
100
|
|
|
94
101
|
[tabs, tab_panels]
|
|
95
102
|
end
|
|
103
|
+
|
|
104
|
+
# Parse a tab item header. A leading `disabled` token (case-sensitive,
|
|
105
|
+
# exactly `disabled` or `disabled `-prefixed) flags the tab as disabled and
|
|
106
|
+
# is stripped from the label; otherwise the label is the stripped title,
|
|
107
|
+
# unchanged. Mirrors accordion's leading item flags.
|
|
108
|
+
def parse_tab_header(title)
|
|
109
|
+
stripped = title.to_s.strip
|
|
110
|
+
return [stripped, false] unless stripped == 'disabled' || stripped.start_with?('disabled ')
|
|
111
|
+
|
|
112
|
+
[stripped.sub(/\Adisabled\s*/, ''), true]
|
|
113
|
+
end
|
|
96
114
|
end
|
|
97
115
|
end
|
|
98
116
|
end
|
|
@@ -13,15 +13,18 @@ module Markawesome
|
|
|
13
13
|
# Alternative block syntax: :::wa-tooltip params\nanchor\n>>>\ntip\n:::
|
|
14
14
|
#
|
|
15
15
|
# Params: space-separated tokens (order doesn't matter)
|
|
16
|
-
# Placement: top (default), bottom, left, right
|
|
17
|
-
#
|
|
16
|
+
# Placement: top (default), bottom, left, right, plus the eight aligned
|
|
17
|
+
# variants (top-start, top-end, right-start, …) — the full wa-tooltip surface
|
|
18
|
+
# Distance: distance:N (e.g., distance:10) — offset away from the target
|
|
19
|
+
# Skidding: skidding:N (e.g., skidding:12, skidding:-4) — offset along the target
|
|
18
20
|
#
|
|
19
21
|
# Tip content is plain text (HTML-escaped), with literal `\n` rendered as
|
|
20
22
|
# <br> — the same surface as the popover's inline form. Tooltips hold brief
|
|
21
23
|
# text, so there is no markdown body.
|
|
22
24
|
class TooltipTransformer < BaseTransformer
|
|
23
25
|
TOOLTIP_ATTRIBUTES = {
|
|
24
|
-
placement: %w[top
|
|
26
|
+
placement: %w[top top-start top-end right right-start right-end
|
|
27
|
+
bottom bottom-start bottom-end left left-start left-end]
|
|
25
28
|
}.freeze
|
|
26
29
|
|
|
27
30
|
# Inline regex (single-line, no newlines allowed): capture 1 = params+anchor,
|
|
@@ -43,12 +46,12 @@ module Markawesome
|
|
|
43
46
|
tip_text = matchdata[2].strip
|
|
44
47
|
|
|
45
48
|
params_string, anchor_text = parse_inline_anchor_and_params(combined)
|
|
46
|
-
placement, distance = parse_parameters(params_string)
|
|
49
|
+
placement, distance, skidding = parse_parameters(params_string)
|
|
47
50
|
|
|
48
51
|
tooltip_id = generate_tooltip_id(anchor_text, tip_text, seen_ids)
|
|
49
52
|
|
|
50
53
|
build_tooltip_html(tooltip_id, anchor_text, tip_text,
|
|
51
|
-
{ placement: placement, distance: distance })
|
|
54
|
+
{ placement: placement, distance: distance, skidding: skidding })
|
|
52
55
|
end
|
|
53
56
|
}
|
|
54
57
|
|
|
@@ -59,12 +62,12 @@ module Markawesome
|
|
|
59
62
|
anchor_text = matchdata[2].strip
|
|
60
63
|
tip_text = matchdata[3].strip
|
|
61
64
|
|
|
62
|
-
placement, distance = parse_parameters(params_string)
|
|
65
|
+
placement, distance, skidding = parse_parameters(params_string)
|
|
63
66
|
|
|
64
67
|
tooltip_id = generate_tooltip_id(anchor_text, tip_text, seen_ids)
|
|
65
68
|
|
|
66
69
|
build_tooltip_html(tooltip_id, anchor_text, tip_text,
|
|
67
|
-
{ placement: placement, distance: distance })
|
|
70
|
+
{ placement: placement, distance: distance, skidding: skidding })
|
|
68
71
|
end
|
|
69
72
|
}
|
|
70
73
|
|
|
@@ -99,17 +102,19 @@ module Markawesome
|
|
|
99
102
|
private
|
|
100
103
|
|
|
101
104
|
def parse_parameters(params_string)
|
|
102
|
-
return ['top', nil] if params_string.nil? || params_string.strip.empty?
|
|
105
|
+
return ['top', nil, nil] if params_string.nil? || params_string.strip.empty?
|
|
103
106
|
|
|
104
107
|
attributes = AttributeParser.parse(params_string, TOOLTIP_ATTRIBUTES)
|
|
105
108
|
placement = attributes[:placement] || 'top'
|
|
106
109
|
|
|
107
|
-
# Look for distance:N
|
|
110
|
+
# Look for distance:N / skidding:N parameters (rightmost-wins; skidding may be negative)
|
|
108
111
|
tokens = params_string.strip.split(/\s+/)
|
|
109
112
|
distance_token = tokens.reverse.find { |token| token.match?(/^distance:\d+$/) }
|
|
110
113
|
distance = distance_token&.sub('distance:', '')
|
|
114
|
+
skidding_token = tokens.reverse.find { |token| token.match?(/^skidding:-?\d+$/) }
|
|
115
|
+
skidding = skidding_token&.sub('skidding:', '')
|
|
111
116
|
|
|
112
|
-
[placement, distance]
|
|
117
|
+
[placement, distance, skidding]
|
|
113
118
|
end
|
|
114
119
|
|
|
115
120
|
def generate_tooltip_id(anchor_text, tip_text, seen_ids)
|
|
@@ -147,7 +152,8 @@ module Markawesome
|
|
|
147
152
|
|
|
148
153
|
def tooltip_param?(token)
|
|
149
154
|
TOOLTIP_ATTRIBUTES.any? { |_attr, values| values.include?(token) } ||
|
|
150
|
-
token.match?(/^distance:\d+$/)
|
|
155
|
+
token.match?(/^distance:\d+$/) ||
|
|
156
|
+
token.match?(/^skidding:-?\d+$/)
|
|
151
157
|
end
|
|
152
158
|
|
|
153
159
|
def build_tooltip_html(tooltip_id, anchor_text, tip_text, options)
|
|
@@ -157,6 +163,7 @@ module Markawesome
|
|
|
157
163
|
tooltip_attrs = ["for=\"#{tooltip_id}\""]
|
|
158
164
|
tooltip_attrs << "placement=\"#{options[:placement]}\""
|
|
159
165
|
tooltip_attrs << "distance=\"#{options[:distance]}\"" if options[:distance]
|
|
166
|
+
tooltip_attrs << "skidding=\"#{options[:skidding]}\"" if options[:skidding]
|
|
160
167
|
|
|
161
168
|
anchor = build_anchor(tooltip_id, anchor_content)
|
|
162
169
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_transformer'
|
|
4
|
+
require_relative '../icon_slot_parser'
|
|
5
|
+
|
|
6
|
+
module Markawesome
|
|
7
|
+
# Transforms tree syntax into wa-tree / wa-tree-item elements from a nested
|
|
8
|
+
# Markdown bullet list.
|
|
9
|
+
# Primary syntax:
|
|
10
|
+
# ||||||open?
|
|
11
|
+
# - icon:folder? expanded? Label
|
|
12
|
+
# - child label
|
|
13
|
+
# ||||||
|
|
14
|
+
# Alternative syntax: :::wa-tree open? ...same list... :::
|
|
15
|
+
#
|
|
16
|
+
# Web Awesome's tree is fundamentally a *selection* control, which is
|
|
17
|
+
# interactive (needs JS). On a static site we deliberately emit a
|
|
18
|
+
# display/navigation-only tree: visual hierarchy via nesting, initial expand
|
|
19
|
+
# state, and leading folder/file icons — all declarative and static-safe. We
|
|
20
|
+
# skip selection, lazy, selected, and selection events entirely.
|
|
21
|
+
#
|
|
22
|
+
# Fence token:
|
|
23
|
+
# - open (alias expanded) -> mark every branch (node with children) expanded
|
|
24
|
+
# Per-node leading tokens (stripped from the label):
|
|
25
|
+
# - expanded -> force this one branch open
|
|
26
|
+
# - icon:name -> leading content <wa-icon name="name"> on the item
|
|
27
|
+
# The remaining text is the (plain-text, HTML-escaped) label.
|
|
28
|
+
#
|
|
29
|
+
# expanded is emitted only on nodes that HAVE children AND (fence open OR the
|
|
30
|
+
# node's own expanded flag); leaves never get expanded.
|
|
31
|
+
#
|
|
32
|
+
# WA runtime caveat (verified against the WA 3.9.0 kit): <wa-tree-item> only
|
|
33
|
+
# honors a static `expanded` on items that are VISIBLE at load, so in practice
|
|
34
|
+
# `open` expands the TOP-LEVEL branches and deeper branches stay collapsed
|
|
35
|
+
# until their parent is opened (WA strips `expanded` from nested items at
|
|
36
|
+
# init). We still emit `expanded` on every branch on purpose: it's harmless
|
|
37
|
+
# (WA ignores the nested ones), records authorial intent, and is
|
|
38
|
+
# forward-compatible if WA ever honors nested initial-expand.
|
|
39
|
+
class TreeTransformer < BaseTransformer
|
|
40
|
+
# Content slot: emits <wa-icon name="..."> with no slot attribute.
|
|
41
|
+
ICON_SLOTS = {
|
|
42
|
+
default: 'content',
|
|
43
|
+
slots: %w[content],
|
|
44
|
+
slot_map: { 'content' => 'content' }
|
|
45
|
+
}.freeze
|
|
46
|
+
|
|
47
|
+
ITEM_FLAGS = %w[expanded].freeze
|
|
48
|
+
FENCE_TOKENS = %w[open expanded].freeze
|
|
49
|
+
TAB_WIDTH = 4
|
|
50
|
+
|
|
51
|
+
PRIMARY_REGEX = /^\|{6}[ \t]*([^\n]*)\n(.*?)\n\|{6}/m
|
|
52
|
+
ALTERNATIVE_REGEX = /^:::wa-tree[ \t]*([^\n]*)\n(.*?)\n:::/m
|
|
53
|
+
LIST_LINE_REGEX = /^(\s*)[-*+]\s+(.*)$/
|
|
54
|
+
|
|
55
|
+
def self.transform(content)
|
|
56
|
+
transform_proc = proc do |params_string, body, _third|
|
|
57
|
+
fence_open = fence_open?(params_string)
|
|
58
|
+
nodes = parse_lines(body)
|
|
59
|
+
"<wa-tree>#{build_items(nodes, fence_open)}</wa-tree>"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
patterns = dual_syntax_patterns(PRIMARY_REGEX, ALTERNATIVE_REGEX, transform_proc)
|
|
63
|
+
apply_multiple_patterns(content, patterns)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Degrade to a clean nested Markdown list (2-space indent per depth, tokens
|
|
67
|
+
# stripped, fence removed).
|
|
68
|
+
def self.render_as_markdown(content, _options = {})
|
|
69
|
+
transform_proc = proc do |_params_string, body, _third|
|
|
70
|
+
nodes = parse_lines(body)
|
|
71
|
+
render_list(nodes, -1, { pos: 0 }, 0)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
patterns = dual_syntax_patterns(PRIMARY_REGEX, ALTERNATIVE_REGEX, transform_proc)
|
|
75
|
+
apply_multiple_patterns(content, patterns)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
class << self
|
|
79
|
+
private
|
|
80
|
+
|
|
81
|
+
def fence_open?(params_string)
|
|
82
|
+
params_string.to_s.strip.split(/\s+/).any? { |t| FENCE_TOKENS.include?(t) }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Keep only list lines; record each line's indent width and its raw text
|
|
86
|
+
# (everything after the bullet). Blank/non-list lines are skipped.
|
|
87
|
+
def parse_lines(body)
|
|
88
|
+
nodes = []
|
|
89
|
+
body.to_s.each_line do |line|
|
|
90
|
+
match = LIST_LINE_REGEX.match(line.chomp)
|
|
91
|
+
next unless match
|
|
92
|
+
|
|
93
|
+
nodes << { indent: indent_width(match[1]), raw: match[2] }
|
|
94
|
+
end
|
|
95
|
+
nodes
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def indent_width(whitespace)
|
|
99
|
+
whitespace.to_s.chars.sum { |char| char == "\t" ? TAB_WIDTH : 1 }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def build_items(nodes, fence_open)
|
|
103
|
+
helper(nodes, -1, { pos: 0 }, fence_open)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Pointer + recursion comparing actual indent values (width-agnostic, no
|
|
107
|
+
# fixed step assumed): children are strictly more indented than the parent.
|
|
108
|
+
def helper(nodes, parent_indent, state, fence_open)
|
|
109
|
+
out = +''
|
|
110
|
+
while state[:pos] < nodes.length && nodes[state[:pos]][:indent] > parent_indent
|
|
111
|
+
node = nodes[state[:pos]]
|
|
112
|
+
current = node[:indent]
|
|
113
|
+
state[:pos] += 1
|
|
114
|
+
children_html = helper(nodes, current, state, fence_open)
|
|
115
|
+
out << emit_item(node, children_html, fence_open)
|
|
116
|
+
end
|
|
117
|
+
out
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def emit_item(node, children_html, fence_open)
|
|
121
|
+
icon_result = IconSlotParser.parse(node[:raw], ICON_SLOTS)
|
|
122
|
+
flags, label = parse_item_flags_and_label(icon_result[:remaining])
|
|
123
|
+
has_children = !children_html.empty?
|
|
124
|
+
expanded = has_children && (fence_open || flags.include?('expanded'))
|
|
125
|
+
|
|
126
|
+
attrs = expanded ? ' expanded' : ''
|
|
127
|
+
icon_html = IconSlotParser.to_html(icon_result[:icons], ICON_SLOTS[:slot_map])
|
|
128
|
+
"<wa-tree-item#{attrs}>#{icon_html}#{escape_html(label)}#{children_html}</wa-tree-item>"
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def render_list(nodes, parent_indent, state, depth)
|
|
132
|
+
lines = []
|
|
133
|
+
while state[:pos] < nodes.length && nodes[state[:pos]][:indent] > parent_indent
|
|
134
|
+
node = nodes[state[:pos]]
|
|
135
|
+
current = node[:indent]
|
|
136
|
+
state[:pos] += 1
|
|
137
|
+
_flags, label = parse_item_flags_and_label(IconSlotParser.parse(node[:raw], ICON_SLOTS)[:remaining])
|
|
138
|
+
lines << "#{' ' * depth}- #{label}"
|
|
139
|
+
child = render_list(nodes, current, state, depth + 1)
|
|
140
|
+
lines << child unless child.empty?
|
|
141
|
+
end
|
|
142
|
+
lines.join("\n")
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Consume leading expanded tokens; the remainder is the label.
|
|
146
|
+
def parse_item_flags_and_label(remaining)
|
|
147
|
+
tokens = remaining.to_s.strip.split(/\s+/)
|
|
148
|
+
flags = []
|
|
149
|
+
flags << tokens.shift while tokens.any? && ITEM_FLAGS.include?(tokens.first)
|
|
150
|
+
[flags, tokens.join(' ')]
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def escape_html(text)
|
|
154
|
+
text.to_s
|
|
155
|
+
.gsub('&', '&')
|
|
156
|
+
.gsub('<', '<')
|
|
157
|
+
.gsub('>', '>')
|
|
158
|
+
.gsub('"', '"')
|
|
159
|
+
.gsub("'", ''')
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_transformer'
|
|
4
|
+
require_relative '../attribute_parser'
|
|
5
|
+
|
|
6
|
+
module Markawesome
|
|
7
|
+
# Transforms video syntax into Web Awesome's two media components:
|
|
8
|
+
# <wa-video> — a single embedded video with custom controls
|
|
9
|
+
# <wa-video-playlist> — a playlist wrapping multiple <wa-video> children
|
|
10
|
+
#
|
|
11
|
+
# Single video
|
|
12
|
+
# Primary: ;;;tokens\n[Title](src)\n\n;;;
|
|
13
|
+
# Alternative: :::wa-video tokens\n…\n:::
|
|
14
|
+
#
|
|
15
|
+
# Playlist (a ;;;;;; container wrapping bare ;;; items, mirroring carousel)
|
|
16
|
+
# Primary: ;;;;;;tokens\n;;;\n[Title](src)\n;;;\n…\n;;;;;;
|
|
17
|
+
# Alternative: :::wa-video-playlist tokens\n;;;\n…\n;;;\n:::
|
|
18
|
+
#
|
|
19
|
+
# Body: the first markdown link `[text](url)` supplies `title`/`src`; the first
|
|
20
|
+
# markdown image `` supplies `poster`. A block with no link (no
|
|
21
|
+
# `src`) is left untransformed.
|
|
22
|
+
#
|
|
23
|
+
# Tokens: `controls:none|standard|full` and `preload:auto|metadata|none`
|
|
24
|
+
# (enum-validated, invalid values dropped) plus the boolean flags
|
|
25
|
+
# `autoplay`, `autoplay-muted`, `autoplay-on-visible`, `loop`, `muted`.
|
|
26
|
+
# Playlist children omit `controls` (the container forwards it to each child).
|
|
27
|
+
class VideoTransformer < BaseTransformer
|
|
28
|
+
# Boolean flags, matched as whole tokens so `autoplay-muted` never triggers
|
|
29
|
+
# `autoplay`. Parsed via AttributeParser (rightmost-wins, order-independent).
|
|
30
|
+
VIDEO_FLAGS = {
|
|
31
|
+
autoplay: %w[autoplay],
|
|
32
|
+
'autoplay-muted': %w[autoplay-muted],
|
|
33
|
+
'autoplay-on-visible': %w[autoplay-on-visible],
|
|
34
|
+
loop: %w[loop],
|
|
35
|
+
muted: %w[muted]
|
|
36
|
+
}.freeze
|
|
37
|
+
|
|
38
|
+
# Deterministic emission order for the boolean flags.
|
|
39
|
+
FLAG_ORDER = %w[autoplay autoplay-muted autoplay-on-visible loop muted].freeze
|
|
40
|
+
|
|
41
|
+
CONTROLS_VALUES = %w[none standard full].freeze
|
|
42
|
+
PRELOAD_VALUES = %w[auto metadata none].freeze
|
|
43
|
+
|
|
44
|
+
# Playlist consumes its inner ;;; items first; the bare `;;;\n` item open
|
|
45
|
+
# (no params) is load-bearing — it stops the closing `;;;;;;` from being
|
|
46
|
+
# mis-read as another item (mirrors carousel's `~~~`/`~~~~~~` trick).
|
|
47
|
+
PLAYLIST_PRIMARY = /^;{6}([^\n]*)\n((?:;;;\n(?:.*?\n)?;;;\n?)+);{6}/m
|
|
48
|
+
PLAYLIST_ALT = /^:::wa-video-playlist\s*([^\n]*)\n(.*?)\n:::/m
|
|
49
|
+
# `(?!;)` keeps the single open from matching a leftover `;;;;;;` fence.
|
|
50
|
+
SINGLE_PRIMARY = /^;;;(?!;)([^\n]*)\n(.*?)\n^;;;$/m
|
|
51
|
+
SINGLE_ALT = /^:::wa-video\s*([^\n]*)\n(.*?)\n:::/m
|
|
52
|
+
ITEM_REGEX = /;;;\n(.*?);;;(?:\n|$)/m
|
|
53
|
+
|
|
54
|
+
# First markdown link that is not the `![…]()` of an image (negative
|
|
55
|
+
# lookbehind on `!`) → title + src.
|
|
56
|
+
LINK_REGEX = /(?<!!)\[([^\]]+)\]\(([^)]+)\)/
|
|
57
|
+
# First markdown image → poster.
|
|
58
|
+
IMAGE_REGEX = /!\[([^\]]*)\]\(([^)]+)\)/
|
|
59
|
+
|
|
60
|
+
def self.transform(content)
|
|
61
|
+
patterns = [
|
|
62
|
+
{ regex: PLAYLIST_PRIMARY, block: proc { |_m, md| build_playlist(md[1], md[2]) } },
|
|
63
|
+
{ regex: PLAYLIST_ALT, block: proc { |_m, md| build_playlist(md[1], md[2]) } },
|
|
64
|
+
{ regex: SINGLE_PRIMARY, block: proc { |m, md| build_single(md[1], md[2]) || m } },
|
|
65
|
+
{ regex: SINGLE_ALT, block: proc { |m, md| build_single(md[1], md[2]) || m } }
|
|
66
|
+
]
|
|
67
|
+
apply_multiple_patterns(content, patterns)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self.render_as_markdown(content, _options = {})
|
|
71
|
+
patterns = [
|
|
72
|
+
{ regex: PLAYLIST_PRIMARY, block: proc { |_m, md| render_playlist_markdown(md[2]) } },
|
|
73
|
+
{ regex: PLAYLIST_ALT, block: proc { |_m, md| render_playlist_markdown(md[2]) } },
|
|
74
|
+
{ regex: SINGLE_PRIMARY, block: proc { |m, md| render_single_markdown(md[2]) || m } },
|
|
75
|
+
{ regex: SINGLE_ALT, block: proc { |m, md| render_single_markdown(md[2]) || m } }
|
|
76
|
+
]
|
|
77
|
+
apply_multiple_patterns(content, patterns)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
class << self
|
|
81
|
+
private
|
|
82
|
+
|
|
83
|
+
def build_single(params, body)
|
|
84
|
+
build_video(params, body, suppress_controls: false)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def build_playlist(params, body)
|
|
88
|
+
controls = parse_tokens(params)[:controls]
|
|
89
|
+
controls_attr = controls ? " controls=\"#{controls}\"" : ''
|
|
90
|
+
children = extract_items(body).filter_map do |item_body|
|
|
91
|
+
build_video('', item_body, suppress_controls: true)
|
|
92
|
+
end
|
|
93
|
+
"<wa-video-playlist#{controls_attr}>#{children.join}</wa-video-playlist>"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Returns the <wa-video> HTML, or nil when the body has no link (no `src`),
|
|
97
|
+
# signalling the caller to leave the block untransformed.
|
|
98
|
+
def build_video(params, body, suppress_controls:)
|
|
99
|
+
tokens = parse_tokens(params)
|
|
100
|
+
title, src, poster = extract_link_and_image(body)
|
|
101
|
+
return nil unless src
|
|
102
|
+
|
|
103
|
+
parts = ["src=\"#{escape_html(src)}\""]
|
|
104
|
+
parts << "poster=\"#{escape_html(poster)}\"" if poster
|
|
105
|
+
parts << "title=\"#{escape_html(title)}\"" if title && !title.empty?
|
|
106
|
+
parts << "controls=\"#{tokens[:controls]}\"" if tokens[:controls] && !suppress_controls
|
|
107
|
+
parts << "preload=\"#{tokens[:preload]}\"" if tokens[:preload]
|
|
108
|
+
FLAG_ORDER.each { |flag| parts << flag if tokens[:flags].include?(flag) }
|
|
109
|
+
|
|
110
|
+
"<wa-video #{parts.join(' ')}></wa-video>"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def parse_tokens(params)
|
|
114
|
+
result = { controls: nil, preload: nil, flags: [] }
|
|
115
|
+
params.to_s.strip.split(/\s+/).each do |token|
|
|
116
|
+
if (m = token.match(/\Acontrols:(.+)\z/)) && CONTROLS_VALUES.include?(m[1])
|
|
117
|
+
result[:controls] = m[1]
|
|
118
|
+
elsif (m = token.match(/\Apreload:(.+)\z/)) && PRELOAD_VALUES.include?(m[1])
|
|
119
|
+
result[:preload] = m[1]
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
result[:flags] = AttributeParser.parse(params, VIDEO_FLAGS).keys.map(&:to_s)
|
|
123
|
+
result
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def extract_items(body)
|
|
127
|
+
body.scan(ITEM_REGEX).map { |match| match[0] }
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def extract_link_and_image(body)
|
|
131
|
+
link = body.match(LINK_REGEX)
|
|
132
|
+
image = body.match(IMAGE_REGEX)
|
|
133
|
+
[link && link[1], link && link[2], image && image[2]]
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def render_single_markdown(body)
|
|
137
|
+
title, src, = extract_link_and_image(body)
|
|
138
|
+
return nil unless src
|
|
139
|
+
|
|
140
|
+
"[#{title.to_s.empty? ? src : title}](#{src})"
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def render_playlist_markdown(body)
|
|
144
|
+
extract_items(body).filter_map do |item_body|
|
|
145
|
+
title, src, = extract_link_and_image(item_body)
|
|
146
|
+
next unless src
|
|
147
|
+
|
|
148
|
+
"- [#{title.to_s.empty? ? src : title}](#{src})"
|
|
149
|
+
end.join("\n")
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def escape_html(text)
|
|
153
|
+
text.to_s.gsub('&', '&').gsub('<', '<').gsub('>', '>')
|
|
154
|
+
.gsub('"', '"').gsub("'", ''')
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
@@ -12,12 +12,16 @@ require_relative 'transformers/card_transformer'
|
|
|
12
12
|
require_relative 'transformers/carousel_transformer'
|
|
13
13
|
require_relative 'transformers/comparison_transformer'
|
|
14
14
|
require_relative 'transformers/copy_button_transformer'
|
|
15
|
+
require_relative 'transformers/date_transformer'
|
|
15
16
|
require_relative 'transformers/details_transformer'
|
|
16
17
|
require_relative 'transformers/dialog_transformer'
|
|
17
18
|
require_relative 'transformers/icon_transformer'
|
|
18
19
|
require_relative 'transformers/image_dialog_transformer'
|
|
19
20
|
require_relative 'transformers/layout_transformer'
|
|
20
21
|
require_relative 'transformers/popover_transformer'
|
|
22
|
+
require_relative 'transformers/random_content_transformer'
|
|
21
23
|
require_relative 'transformers/tabs_transformer'
|
|
22
24
|
require_relative 'transformers/tag_transformer'
|
|
23
25
|
require_relative 'transformers/tooltip_transformer'
|
|
26
|
+
require_relative 'transformers/tree_transformer'
|
|
27
|
+
require_relative 'transformers/video_transformer'
|
data/lib/markawesome/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: markawesome
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.18.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Janne Waren
|
|
@@ -93,15 +93,19 @@ files:
|
|
|
93
93
|
- lib/markawesome/transformers/carousel_transformer.rb
|
|
94
94
|
- lib/markawesome/transformers/comparison_transformer.rb
|
|
95
95
|
- lib/markawesome/transformers/copy_button_transformer.rb
|
|
96
|
+
- lib/markawesome/transformers/date_transformer.rb
|
|
96
97
|
- lib/markawesome/transformers/details_transformer.rb
|
|
97
98
|
- lib/markawesome/transformers/dialog_transformer.rb
|
|
98
99
|
- lib/markawesome/transformers/icon_transformer.rb
|
|
99
100
|
- lib/markawesome/transformers/image_dialog_transformer.rb
|
|
100
101
|
- lib/markawesome/transformers/layout_transformer.rb
|
|
101
102
|
- lib/markawesome/transformers/popover_transformer.rb
|
|
103
|
+
- lib/markawesome/transformers/random_content_transformer.rb
|
|
102
104
|
- lib/markawesome/transformers/tabs_transformer.rb
|
|
103
105
|
- lib/markawesome/transformers/tag_transformer.rb
|
|
104
106
|
- lib/markawesome/transformers/tooltip_transformer.rb
|
|
107
|
+
- lib/markawesome/transformers/tree_transformer.rb
|
|
108
|
+
- lib/markawesome/transformers/video_transformer.rb
|
|
105
109
|
- lib/markawesome/version.rb
|
|
106
110
|
- markawesome.gemspec
|
|
107
111
|
homepage: https://github.com/jannewaren/markawesome
|