MCPcopy
hub / github.com/marktext/marktext / htmlRuby

Function htmlRuby

packages/muya/src/inlineRenderer/renderer/htmlRuby.ts:6–55  ·  view source on GitHub ↗
(
    this: Renderer,
    {
        h,
        cursor,
        block,
        token,
        outerClass,
    }: ISyntaxRenderOptions & { token: HTMLTagToken },
)

Source from the content-addressed store, hash-verified

4import { htmlToVNode } from '../../utils/snabbdom';
5
6export default function htmlRuby(
7 this: Renderer,
8 {
9 h,
10 cursor,
11 block,
12 token,
13 outerClass,
14 }: ISyntaxRenderOptions & { token: HTMLTagToken },
15) {
16 const className = this.getClassName(outerClass, block, token, cursor);
17 const { children } = token;
18 const { start, end } = token.range;
19 const content = this.highlight(h, block, start, end, token);
20 const vNode = htmlToVNode(token.raw);
21 const previewSelector = `span.${CLASS_NAMES.MU_RUBY_RENDER}`;
22
23 return children?.length
24 ? [
25 h(`span.${className}.${CLASS_NAMES.MU_RUBY}`, [
26 h(
27 `span.${CLASS_NAMES.MU_INLINE_RULE}.${CLASS_NAMES.MU_RUBY_TEXT}`,
28 content,
29 ),
30 h(
31 previewSelector,
32 {
33 attrs: {
34 contenteditable: 'false',
35 spellcheck: 'false',
36 },
37 dataset: {
38 start: String(start + 6), // '<ruby>'.length
39 end: String(end - 7), // '</ruby>'.length
40 },
41 },
42 vNode,
43 ),
44 ]),
45 // if children is empty string, no need to render ruby characters...
46 ]
47 : [
48 h(`span.${className}.${CLASS_NAMES.MU_RUBY}`, [
49 h(
50 `span.${CLASS_NAMES.MU_INLINE_RULE}.${CLASS_NAMES.MU_RUBY_TEXT}`,
51 content,
52 ),
53 ]),
54 ];
55}

Callers

nothing calls this directly

Calls 4

htmlToVNodeFunction · 0.90
hFunction · 0.85
highlightMethod · 0.80
getClassNameMethod · 0.45

Tested by

no test coverage detected