@domenico-esposito/react-native-markdown-editor 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/.eslintrc.js +5 -0
- package/README.md +265 -0
- package/build/MarkdownRenderer.d.ts +12 -0
- package/build/MarkdownRenderer.d.ts.map +1 -0
- package/build/MarkdownRenderer.js +165 -0
- package/build/MarkdownRenderer.js.map +1 -0
- package/build/MarkdownTextInput.d.ts +10 -0
- package/build/MarkdownTextInput.d.ts.map +1 -0
- package/build/MarkdownTextInput.js +233 -0
- package/build/MarkdownTextInput.js.map +1 -0
- package/build/MarkdownToolbar.d.ts +11 -0
- package/build/MarkdownToolbar.d.ts.map +1 -0
- package/build/MarkdownToolbar.js +98 -0
- package/build/MarkdownToolbar.js.map +1 -0
- package/build/index.d.ts +14 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +11 -0
- package/build/index.js.map +1 -0
- package/build/markdownCore.types.d.ts +321 -0
- package/build/markdownCore.types.d.ts.map +1 -0
- package/build/markdownCore.types.js +2 -0
- package/build/markdownCore.types.js.map +1 -0
- package/build/markdownHighlight.d.ts +31 -0
- package/build/markdownHighlight.d.ts.map +1 -0
- package/build/markdownHighlight.js +378 -0
- package/build/markdownHighlight.js.map +1 -0
- package/build/markdownHighlight.types.d.ts +48 -0
- package/build/markdownHighlight.types.d.ts.map +1 -0
- package/build/markdownHighlight.types.js +9 -0
- package/build/markdownHighlight.types.js.map +1 -0
- package/build/markdownParser.d.ts +16 -0
- package/build/markdownParser.d.ts.map +1 -0
- package/build/markdownParser.js +309 -0
- package/build/markdownParser.js.map +1 -0
- package/build/markdownRendererDefaults.d.ts +113 -0
- package/build/markdownRendererDefaults.d.ts.map +1 -0
- package/build/markdownRendererDefaults.js +174 -0
- package/build/markdownRendererDefaults.js.map +1 -0
- package/build/markdownSegment.types.d.ts +22 -0
- package/build/markdownSegment.types.d.ts.map +1 -0
- package/build/markdownSegment.types.js +2 -0
- package/build/markdownSegment.types.js.map +1 -0
- package/build/markdownSegmentDefaults.d.ts +43 -0
- package/build/markdownSegmentDefaults.d.ts.map +1 -0
- package/build/markdownSegmentDefaults.js +176 -0
- package/build/markdownSegmentDefaults.js.map +1 -0
- package/build/markdownSyntaxUtils.d.ts +58 -0
- package/build/markdownSyntaxUtils.d.ts.map +1 -0
- package/build/markdownSyntaxUtils.js +98 -0
- package/build/markdownSyntaxUtils.js.map +1 -0
- package/build/markdownToolbarActions.d.ts +12 -0
- package/build/markdownToolbarActions.d.ts.map +1 -0
- package/build/markdownToolbarActions.js +212 -0
- package/build/markdownToolbarActions.js.map +1 -0
- package/build/useMarkdownEditor.d.ts +10 -0
- package/build/useMarkdownEditor.d.ts.map +1 -0
- package/build/useMarkdownEditor.js +219 -0
- package/build/useMarkdownEditor.js.map +1 -0
- package/jest.config.js +10 -0
- package/package.json +45 -0
- package/src/MarkdownRenderer.tsx +240 -0
- package/src/MarkdownTextInput.tsx +263 -0
- package/src/MarkdownToolbar.tsx +126 -0
- package/src/index.ts +31 -0
- package/src/markdownCore.types.ts +405 -0
- package/src/markdownHighlight.ts +413 -0
- package/src/markdownHighlight.types.ts +75 -0
- package/src/markdownParser.ts +345 -0
- package/src/markdownRendererDefaults.tsx +207 -0
- package/src/markdownSegment.types.ts +24 -0
- package/src/markdownSegmentDefaults.tsx +208 -0
- package/src/markdownSyntaxUtils.ts +139 -0
- package/src/markdownToolbarActions.ts +296 -0
- package/src/useMarkdownEditor.ts +265 -0
- package/tsconfig.json +9 -0
- package/tsconfig.test.json +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownRendererDefaults.js","sourceRoot":"","sources":["../src/markdownRendererDefaults.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAI7D,8EA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YAAY,EAAE,CAAC;QACf,OAAO,EAAE,EAAE;KACX;IACD,iBAAiB,EAAE;QAClB,SAAS,EAAE,YAAY;QACvB,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,KAAK;QACjB,eAAe,EAAE,SAAS;QAC1B,YAAY,EAAE,CAAC;QACf,iBAAiB,EAAE,CAAC;QACpB,eAAe,EAAE,CAAC;QAClB,YAAY,EAAE,CAAC;KACf;IACD,aAAa,EAAE;QACd,UAAU,EAAE,SAAS;KACrB;IACD,UAAU,EAAE;QACX,eAAe,EAAE,CAAC;QAClB,eAAe,EAAE,SAAS;QAC1B,WAAW,EAAE,EAAE;KACf;IACD,cAAc,EAAE;QACf,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,SAAS;QAC5B,cAAc,EAAE,CAAC;KACjB;IACD,IAAI,EAAE;QACL,GAAG,EAAE,CAAC;KACN;IACD,QAAQ,EAAE;QACT,aAAa,EAAE,KAAK;KACpB;IACD,IAAI,EAAE;QACL,KAAK,EAAE,SAAS;QAChB,kBAAkB,EAAE,WAAW;KAC/B;IACD,KAAK,EAAE;QACN,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,GAAG;KACX;IACD,cAAc,EAAE;QACf,UAAU,EAAE,QAAQ;KACpB;IACD,QAAQ,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,SAAS;QAChB,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,QAAQ;KACnB;IACD,MAAM,EAAE;QACP,MAAM,EAAE,CAAC;KACT;CACD,CAAC,CAAC","sourcesContent":["/**\n * Default component implementations and styles for {@link MarkdownRenderer}.\n *\n * Each markdown tag has a corresponding default component that provides\n * basic visual styling. Consumers can override any subset via the\n * `components` prop on `MarkdownRenderer`.\n */\n\nimport * as React from 'react';\nimport { Image, StyleSheet, Text, View } from 'react-native';\n\nimport type { MarkdownComponentMap } from './markdownCore.types';\n\n// ---------------------------------------------------------------------------\n// Default components\n// ---------------------------------------------------------------------------\n\nconst DefaultRoot: MarkdownComponentMap['root'] = ({ children, style }) => <View style={[styles.root, style]}>{children}</View>;\n\nconst DefaultParagraph: MarkdownComponentMap['paragraph'] = ({ children }) => <Text style={styles.paragraph}>{children}</Text>;\n\nconst DefaultText: MarkdownComponentMap['text'] = ({ children }) => <Text>{children}</Text>;\n\nconst DefaultHeading1: MarkdownComponentMap['heading1'] = ({ children }) => <Text style={styles.heading1}>{children}</Text>;\n\nconst DefaultHeading2: MarkdownComponentMap['heading2'] = ({ children }) => <Text style={styles.heading2}>{children}</Text>;\n\nconst DefaultHeading3: MarkdownComponentMap['heading3'] = ({ children }) => <Text style={styles.heading3}>{children}</Text>;\n\nconst DefaultHeading4: MarkdownComponentMap['heading4'] = ({ children }) => <Text style={styles.heading4}>{children}</Text>;\n\nconst DefaultHeading5: MarkdownComponentMap['heading5'] = ({ children }) => <Text style={styles.heading5}>{children}</Text>;\n\nconst DefaultHeading6: MarkdownComponentMap['heading6'] = ({ children }) => <Text style={styles.heading6}>{children}</Text>;\n\nconst DefaultBold: MarkdownComponentMap['bold'] = ({ children }) => <Text style={styles.bold}>{children}</Text>;\n\nconst DefaultItalic: MarkdownComponentMap['italic'] = ({ children }) => <Text style={styles.italic}>{children}</Text>;\n\nconst DefaultStrikethrough: MarkdownComponentMap['strikethrough'] = ({ children }) => <Text style={styles.strikethrough}>{children}</Text>;\n\nconst DefaultInlineCode: MarkdownComponentMap['inlineCode'] = ({ children }) => <Text style={styles.inlineCode}>{children}</Text>;\n\nconst DefaultCodeBlock: MarkdownComponentMap['codeBlock'] = ({ text, language }) => (\n\t<View style={styles.codeBlock}>\n\t\t<Text style={styles.codeBlockLanguage}>{language?.trim() || 'Code'}</Text>\n\t\t<Text style={styles.codeBlockText}>{text}</Text>\n\t</View>\n);\n\nconst DefaultBlockquote: MarkdownComponentMap['blockquote'] = ({ children }) => <View style={styles.blockquote}>{children}</View>;\n\nconst DefaultHorizontalRule: MarkdownComponentMap['horizontalRule'] = () => <View style={styles.horizontalRule} />;\n\nconst DefaultSpacer: MarkdownComponentMap['spacer'] = () => <View style={styles.spacer} />;\n\nconst DefaultUnorderedList: MarkdownComponentMap['unorderedList'] = ({ children }) => <View style={styles.list}>{children}</View>;\n\nconst DefaultOrderedList: MarkdownComponentMap['orderedList'] = ({ children }) => <View style={styles.list}>{children}</View>;\n\nconst DefaultListItem: MarkdownComponentMap['listItem'] = ({ children }) => <View style={styles.listItem}>{children}</View>;\n\nconst DefaultLink: MarkdownComponentMap['link'] = ({ children }) => <Text style={styles.link}>{children}</Text>;\n\nconst DefaultImage: MarkdownComponentMap['image'] = ({ src, alt, title }) => (\n\t<View style={styles.imageContainer}>\n\t\t<Image source={{ uri: src }} style={styles.image} resizeMode=\"contain\" accessibilityLabel={alt ?? title} />\n\t\t{alt ? <Text style={styles.imageAlt}>{alt}</Text> : null}\n\t</View>\n);\n\n// ---------------------------------------------------------------------------\n// Component map\n// ---------------------------------------------------------------------------\n\n/** Complete map of default markdown rendering components. */\nexport const DEFAULT_COMPONENTS: MarkdownComponentMap = {\n\troot: DefaultRoot,\n\tparagraph: DefaultParagraph,\n\ttext: DefaultText,\n\theading1: DefaultHeading1,\n\theading2: DefaultHeading2,\n\theading3: DefaultHeading3,\n\theading4: DefaultHeading4,\n\theading5: DefaultHeading5,\n\theading6: DefaultHeading6,\n\tbold: DefaultBold,\n\titalic: DefaultItalic,\n\tstrikethrough: DefaultStrikethrough,\n\tinlineCode: DefaultInlineCode,\n\tcodeBlock: DefaultCodeBlock,\n\tblockquote: DefaultBlockquote,\n\thorizontalRule: DefaultHorizontalRule,\n\tunorderedList: DefaultUnorderedList,\n\torderedList: DefaultOrderedList,\n\tlistItem: DefaultListItem,\n\tlink: DefaultLink,\n\timage: DefaultImage,\n\tspacer: DefaultSpacer,\n};\n\n// ---------------------------------------------------------------------------\n// Styles\n// ---------------------------------------------------------------------------\n\nexport const styles = StyleSheet.create({\n\troot: {\n\t\tgap: 8,\n\t},\n\tparagraph: {\n\t\tcolor: '#1f1f1f',\n\t\tlineHeight: 22,\n\t},\n\theading1: {\n\t\tfontSize: 30,\n\t\tfontWeight: '700',\n\t},\n\theading2: {\n\t\tfontSize: 26,\n\t\tfontWeight: '700',\n\t},\n\theading3: {\n\t\tfontSize: 22,\n\t\tfontWeight: '700',\n\t},\n\theading4: {\n\t\tfontSize: 20,\n\t\tfontWeight: '700',\n\t},\n\theading5: {\n\t\tfontSize: 18,\n\t\tfontWeight: '700',\n\t},\n\theading6: {\n\t\tfontSize: 16,\n\t\tfontWeight: '700',\n\t},\n\tbold: {\n\t\tfontWeight: '700',\n\t},\n\titalic: {\n\t\tfontStyle: 'italic',\n\t},\n\tstrikethrough: {\n\t\ttextDecorationLine: 'line-through' as const,\n\t},\n\tinlineCode: {\n\t\tfontFamily: 'Courier',\n\t\tbackgroundColor: '#f1f1f1',\n\t\tpaddingHorizontal: 4,\n\t\tborderRadius: 4,\n\t},\n\tcodeBlock: {\n\t\tbackgroundColor: '#f1f1f1',\n\t\tborderRadius: 8,\n\t\tpadding: 12,\n\t},\n\tcodeBlockLanguage: {\n\t\talignSelf: 'flex-start',\n\t\tfontSize: 11,\n\t\tfontWeight: '700',\n\t\tbackgroundColor: '#e2e2e2',\n\t\tborderRadius: 4,\n\t\tpaddingHorizontal: 6,\n\t\tpaddingVertical: 2,\n\t\tmarginBottom: 8,\n\t},\n\tcodeBlockText: {\n\t\tfontFamily: 'Courier',\n\t},\n\tblockquote: {\n\t\tborderLeftWidth: 3,\n\t\tborderLeftColor: '#acacac',\n\t\tpaddingLeft: 10,\n\t},\n\thorizontalRule: {\n\t\tborderBottomWidth: 1,\n\t\tborderBottomColor: '#d0d0d0',\n\t\tmarginVertical: 8,\n\t},\n\tlist: {\n\t\tgap: 4,\n\t},\n\tlistItem: {\n\t\tflexDirection: 'row',\n\t},\n\tlink: {\n\t\tcolor: '#2d5eff',\n\t\ttextDecorationLine: 'underline',\n\t},\n\timage: {\n\t\twidth: '100%',\n\t\theight: 200,\n\t},\n\timageContainer: {\n\t\talignItems: 'center',\n\t},\n\timageAlt: {\n\t\tfontSize: 12,\n\t\tcolor: '#6b6b6b',\n\t\tmarginTop: 4,\n\t\ttextAlign: 'center',\n\t},\n\tspacer: {\n\t\theight: 8,\n\t},\n});\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import type { HighlightSegmentType } from './markdownHighlight.types';
|
|
3
|
+
/**
|
|
4
|
+
* Props received by every custom segment component.
|
|
5
|
+
* The component MUST render a Text (or a component that inherits from Text),
|
|
6
|
+
* since segments are children of a TextInput.
|
|
7
|
+
*/
|
|
8
|
+
export type SegmentComponentProps = {
|
|
9
|
+
/** Semantic type of the segment (e.g. 'bold', 'heading', 'code'). */
|
|
10
|
+
type: HighlightSegmentType;
|
|
11
|
+
/** Optional metadata emitted by the highlighter (e.g. heading level, image info). */
|
|
12
|
+
meta?: Record<string, string>;
|
|
13
|
+
/** The segment text content. */
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Map of custom components keyed by segment type.
|
|
18
|
+
* Only the types you want to override need to be specified;
|
|
19
|
+
* unspecified types fall back to defaults.
|
|
20
|
+
*/
|
|
21
|
+
export type SegmentComponentMap = Partial<Record<HighlightSegmentType, ComponentType<SegmentComponentProps>>>;
|
|
22
|
+
//# sourceMappingURL=markdownSegment.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownSegment.types.d.ts","sourceRoot":"","sources":["../src/markdownSegment.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG;IACnC,qEAAqE;IACrE,IAAI,EAAE,oBAAoB,CAAC;IAC3B,qFAAqF;IACrF,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,gCAAgC;IAChC,QAAQ,EAAE,SAAS,CAAC;CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownSegment.types.js","sourceRoot":"","sources":["../src/markdownSegment.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType, ReactNode } from 'react';\n\nimport type { HighlightSegmentType } from './markdownHighlight.types';\n\n/**\n * Props received by every custom segment component.\n * The component MUST render a Text (or a component that inherits from Text),\n * since segments are children of a TextInput.\n */\nexport type SegmentComponentProps = {\n\t/** Semantic type of the segment (e.g. 'bold', 'heading', 'code'). */\n\ttype: HighlightSegmentType;\n\t/** Optional metadata emitted by the highlighter (e.g. heading level, image info). */\n\tmeta?: Record<string, string>;\n\t/** The segment text content. */\n\tchildren: ReactNode;\n};\n\n/**\n * Map of custom components keyed by segment type.\n * Only the types you want to override need to be specified;\n * unspecified types fall back to defaults.\n */\nexport type SegmentComponentMap = Partial<Record<HighlightSegmentType, ComponentType<SegmentComponentProps>>>;\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { TextStyle } from 'react-native';
|
|
3
|
+
import type { HighlightSegmentType } from './markdownHighlight.types';
|
|
4
|
+
import type { SegmentComponentProps } from './markdownSegment.types';
|
|
5
|
+
export declare function getDefaultSegmentStyle(type: HighlightSegmentType, meta?: Record<string, string>): TextStyle;
|
|
6
|
+
/** Default renderer - a plain Text with the default style for the segment type. */
|
|
7
|
+
declare function DefaultTextSegment({ type, meta, children }: SegmentComponentProps): React.JSX.Element;
|
|
8
|
+
export declare const DefaultSegment: typeof DefaultTextSegment;
|
|
9
|
+
/** Default bold - renders bold text. */
|
|
10
|
+
export declare const DefaultBoldSegment: typeof DefaultTextSegment;
|
|
11
|
+
/** Default heading - renders heading text. */
|
|
12
|
+
export declare const DefaultHeadingSegment: typeof DefaultTextSegment;
|
|
13
|
+
/** Default italic - renders italic text. */
|
|
14
|
+
export declare const DefaultItalicSegment: typeof DefaultTextSegment;
|
|
15
|
+
/** Default strikethrough - renders strikethrough text. */
|
|
16
|
+
export declare const DefaultStrikethroughSegment: typeof DefaultTextSegment;
|
|
17
|
+
/** Default inline code - renders code text. */
|
|
18
|
+
export declare const DefaultCodeSegment: typeof DefaultTextSegment;
|
|
19
|
+
/** Default code block - renders code block content. */
|
|
20
|
+
export declare const DefaultCodeBlockSegment: typeof DefaultTextSegment;
|
|
21
|
+
/** Default link label - renders link text. */
|
|
22
|
+
export declare const DefaultLinkSegment: typeof DefaultTextSegment;
|
|
23
|
+
/** Default link URL - renders link URL text. */
|
|
24
|
+
export declare const DefaultLinkUrlSegment: typeof DefaultTextSegment;
|
|
25
|
+
/** Default image - renders image markdown text. */
|
|
26
|
+
export declare const DefaultImageSegment: typeof DefaultTextSegment;
|
|
27
|
+
/** Default blockquote - renders quote text. */
|
|
28
|
+
export declare const DefaultQuoteSegment: typeof DefaultTextSegment;
|
|
29
|
+
/** Default quote marker - renders the > character. */
|
|
30
|
+
export declare const DefaultQuoteMarkerSegment: typeof DefaultTextSegment;
|
|
31
|
+
/** Default delimiter - renders markdown syntax characters. */
|
|
32
|
+
export declare const DefaultDelimiterSegment: typeof DefaultTextSegment;
|
|
33
|
+
/** Default list marker - renders list bullet/number. */
|
|
34
|
+
export declare const DefaultListMarkerSegment: typeof DefaultTextSegment;
|
|
35
|
+
/** Default horizontal rule - renders the rule markers (---, ***, ___). */
|
|
36
|
+
export declare const DefaultHorizontalRuleSegment: typeof DefaultTextSegment;
|
|
37
|
+
/**
|
|
38
|
+
* Complete map of default segment components.
|
|
39
|
+
* Used as fallback when no custom component is provided for a type.
|
|
40
|
+
*/
|
|
41
|
+
export declare const DEFAULT_SEGMENT_COMPONENTS: Record<HighlightSegmentType, React.ComponentType<SegmentComponentProps>>;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=markdownSegmentDefaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownSegmentDefaults.d.ts","sourceRoot":"","sources":["../src/markdownSegmentDefaults.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AA2CrE,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAoF3G;AAMD,mFAAmF;AACnF,iBAAS,kBAAkB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,qBAAqB,qBAE1E;AAED,eAAO,MAAM,cAAc,2BAAqB,CAAC;AAEjD,wCAAwC;AACxC,eAAO,MAAM,kBAAkB,2BAAqB,CAAC;AAErD,8CAA8C;AAC9C,eAAO,MAAM,qBAAqB,2BAAqB,CAAC;AAExD,4CAA4C;AAC5C,eAAO,MAAM,oBAAoB,2BAAqB,CAAC;AAEvD,0DAA0D;AAC1D,eAAO,MAAM,2BAA2B,2BAAqB,CAAC;AAE9D,+CAA+C;AAC/C,eAAO,MAAM,kBAAkB,2BAAqB,CAAC;AAErD,uDAAuD;AACvD,eAAO,MAAM,uBAAuB,2BAAqB,CAAC;AAE1D,8CAA8C;AAC9C,eAAO,MAAM,kBAAkB,2BAAqB,CAAC;AAErD,gDAAgD;AAChD,eAAO,MAAM,qBAAqB,2BAAqB,CAAC;AAExD,mDAAmD;AACnD,eAAO,MAAM,mBAAmB,2BAAqB,CAAC;AAEtD,+CAA+C;AAC/C,eAAO,MAAM,mBAAmB,2BAAqB,CAAC;AAEtD,sDAAsD;AACtD,eAAO,MAAM,yBAAyB,2BAAqB,CAAC;AAE5D,8DAA8D;AAC9D,eAAO,MAAM,uBAAuB,2BAAqB,CAAC;AAE1D,wDAAwD;AACxD,eAAO,MAAM,wBAAwB,2BAAqB,CAAC;AAE3D,0EAA0E;AAC1E,eAAO,MAAM,4BAA4B,2BAAqB,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,oBAAoB,EAAE,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAgB/G,CAAC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Default styling values
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
const COLOR_TEXT = '#1f1f1f';
|
|
7
|
+
const COLOR_DELIMITER = '#a0a0a0';
|
|
8
|
+
const COLOR_CODE = '#c7254e';
|
|
9
|
+
const COLOR_CODE_BG = '#f9f2f4';
|
|
10
|
+
const COLOR_LINK = '#2d5eff';
|
|
11
|
+
const COLOR_LINK_URL = '#8a8a8a';
|
|
12
|
+
const COLOR_IMAGE = '#2d5eff';
|
|
13
|
+
const COLOR_QUOTE = '#6a737d';
|
|
14
|
+
const COLOR_QUOTE_MARKER = '#a0a0a0';
|
|
15
|
+
const COLOR_LIST_MARKER = '#2d5eff';
|
|
16
|
+
const COLOR_HORIZONTAL_RULE = '#a0a0a0';
|
|
17
|
+
const FONT_SIZE = 16;
|
|
18
|
+
const FONT_SIZE_HEADING = Math.round(FONT_SIZE * 1.75);
|
|
19
|
+
const FONT_SIZE_CODE = Math.round(FONT_SIZE * 0.875);
|
|
20
|
+
const LINE_HEIGHT = computeLineHeight(FONT_SIZE);
|
|
21
|
+
const LINE_HEIGHT_CODE = computeLineHeight(FONT_SIZE_CODE);
|
|
22
|
+
function computeLineHeight(fontSize) {
|
|
23
|
+
return Math.ceil(fontSize * 1.5);
|
|
24
|
+
}
|
|
25
|
+
function getHeadingFontSize(level) {
|
|
26
|
+
if (level < 1 || level > 6)
|
|
27
|
+
return FONT_SIZE;
|
|
28
|
+
const t = (level - 1) / 5;
|
|
29
|
+
return Math.round(FONT_SIZE_HEADING + t * (FONT_SIZE - FONT_SIZE_HEADING));
|
|
30
|
+
}
|
|
31
|
+
function getHeadingMetrics(meta) {
|
|
32
|
+
const level = Number.parseInt(meta?.headingLevel ?? '1', 10);
|
|
33
|
+
const fontSize = getHeadingFontSize(Number.isNaN(level) ? 1 : level);
|
|
34
|
+
return {
|
|
35
|
+
fontSize,
|
|
36
|
+
lineHeight: computeLineHeight(fontSize),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function getDefaultSegmentStyle(type, meta) {
|
|
40
|
+
const style = {
|
|
41
|
+
color: COLOR_TEXT,
|
|
42
|
+
fontSize: FONT_SIZE,
|
|
43
|
+
lineHeight: LINE_HEIGHT,
|
|
44
|
+
includeFontPadding: false,
|
|
45
|
+
};
|
|
46
|
+
switch (type) {
|
|
47
|
+
case 'delimiter':
|
|
48
|
+
style.color = COLOR_DELIMITER;
|
|
49
|
+
break;
|
|
50
|
+
case 'heading':
|
|
51
|
+
style.fontWeight = 'bold';
|
|
52
|
+
break;
|
|
53
|
+
case 'bold':
|
|
54
|
+
style.fontWeight = 'bold';
|
|
55
|
+
break;
|
|
56
|
+
case 'italic':
|
|
57
|
+
style.fontStyle = 'italic';
|
|
58
|
+
break;
|
|
59
|
+
case 'strikethrough':
|
|
60
|
+
style.textDecorationLine = 'line-through';
|
|
61
|
+
break;
|
|
62
|
+
case 'code':
|
|
63
|
+
style.color = COLOR_CODE;
|
|
64
|
+
style.backgroundColor = COLOR_CODE_BG;
|
|
65
|
+
style.fontFamily = 'Courier';
|
|
66
|
+
style.fontSize = FONT_SIZE_CODE;
|
|
67
|
+
style.lineHeight = LINE_HEIGHT_CODE;
|
|
68
|
+
break;
|
|
69
|
+
case 'codeBlock':
|
|
70
|
+
style.color = COLOR_CODE;
|
|
71
|
+
style.fontFamily = 'Courier';
|
|
72
|
+
style.fontSize = FONT_SIZE_CODE;
|
|
73
|
+
style.lineHeight = LINE_HEIGHT_CODE;
|
|
74
|
+
break;
|
|
75
|
+
case 'link':
|
|
76
|
+
style.color = COLOR_LINK;
|
|
77
|
+
break;
|
|
78
|
+
case 'linkUrl':
|
|
79
|
+
style.color = COLOR_LINK_URL;
|
|
80
|
+
break;
|
|
81
|
+
case 'image':
|
|
82
|
+
style.color = COLOR_IMAGE;
|
|
83
|
+
break;
|
|
84
|
+
case 'quote':
|
|
85
|
+
style.color = COLOR_QUOTE;
|
|
86
|
+
break;
|
|
87
|
+
case 'quoteMarker':
|
|
88
|
+
style.color = COLOR_QUOTE_MARKER;
|
|
89
|
+
break;
|
|
90
|
+
case 'listMarker':
|
|
91
|
+
style.color = COLOR_LIST_MARKER;
|
|
92
|
+
style.fontWeight = 'bold';
|
|
93
|
+
break;
|
|
94
|
+
case 'horizontalRule':
|
|
95
|
+
style.color = COLOR_HORIZONTAL_RULE;
|
|
96
|
+
style.letterSpacing = 4;
|
|
97
|
+
style.textAlign = 'center';
|
|
98
|
+
break;
|
|
99
|
+
case 'text':
|
|
100
|
+
default:
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const lineContext = meta?.lineContext;
|
|
104
|
+
if (lineContext === 'heading') {
|
|
105
|
+
const { fontSize, lineHeight } = getHeadingMetrics(meta);
|
|
106
|
+
style.fontSize = fontSize;
|
|
107
|
+
style.lineHeight = lineHeight;
|
|
108
|
+
style.fontWeight = 'bold';
|
|
109
|
+
}
|
|
110
|
+
if (lineContext === 'quote' && (type === 'text' || type === 'bold' || type === 'italic' || type === 'strikethrough')) {
|
|
111
|
+
style.color = COLOR_QUOTE;
|
|
112
|
+
}
|
|
113
|
+
if (lineContext === 'codeFence' && type === 'delimiter') {
|
|
114
|
+
style.fontSize = FONT_SIZE_CODE;
|
|
115
|
+
style.lineHeight = LINE_HEIGHT_CODE;
|
|
116
|
+
}
|
|
117
|
+
return style;
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// Default components
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
/** Default renderer - a plain Text with the default style for the segment type. */
|
|
123
|
+
function DefaultTextSegment({ type, meta, children }) {
|
|
124
|
+
return <Text style={getDefaultSegmentStyle(type, meta)}>{children}</Text>;
|
|
125
|
+
}
|
|
126
|
+
export const DefaultSegment = DefaultTextSegment;
|
|
127
|
+
/** Default bold - renders bold text. */
|
|
128
|
+
export const DefaultBoldSegment = DefaultTextSegment;
|
|
129
|
+
/** Default heading - renders heading text. */
|
|
130
|
+
export const DefaultHeadingSegment = DefaultTextSegment;
|
|
131
|
+
/** Default italic - renders italic text. */
|
|
132
|
+
export const DefaultItalicSegment = DefaultTextSegment;
|
|
133
|
+
/** Default strikethrough - renders strikethrough text. */
|
|
134
|
+
export const DefaultStrikethroughSegment = DefaultTextSegment;
|
|
135
|
+
/** Default inline code - renders code text. */
|
|
136
|
+
export const DefaultCodeSegment = DefaultTextSegment;
|
|
137
|
+
/** Default code block - renders code block content. */
|
|
138
|
+
export const DefaultCodeBlockSegment = DefaultTextSegment;
|
|
139
|
+
/** Default link label - renders link text. */
|
|
140
|
+
export const DefaultLinkSegment = DefaultTextSegment;
|
|
141
|
+
/** Default link URL - renders link URL text. */
|
|
142
|
+
export const DefaultLinkUrlSegment = DefaultTextSegment;
|
|
143
|
+
/** Default image - renders image markdown text. */
|
|
144
|
+
export const DefaultImageSegment = DefaultTextSegment;
|
|
145
|
+
/** Default blockquote - renders quote text. */
|
|
146
|
+
export const DefaultQuoteSegment = DefaultTextSegment;
|
|
147
|
+
/** Default quote marker - renders the > character. */
|
|
148
|
+
export const DefaultQuoteMarkerSegment = DefaultTextSegment;
|
|
149
|
+
/** Default delimiter - renders markdown syntax characters. */
|
|
150
|
+
export const DefaultDelimiterSegment = DefaultTextSegment;
|
|
151
|
+
/** Default list marker - renders list bullet/number. */
|
|
152
|
+
export const DefaultListMarkerSegment = DefaultTextSegment;
|
|
153
|
+
/** Default horizontal rule - renders the rule markers (---, ***, ___). */
|
|
154
|
+
export const DefaultHorizontalRuleSegment = DefaultTextSegment;
|
|
155
|
+
/**
|
|
156
|
+
* Complete map of default segment components.
|
|
157
|
+
* Used as fallback when no custom component is provided for a type.
|
|
158
|
+
*/
|
|
159
|
+
export const DEFAULT_SEGMENT_COMPONENTS = {
|
|
160
|
+
text: DefaultSegment,
|
|
161
|
+
delimiter: DefaultDelimiterSegment,
|
|
162
|
+
heading: DefaultHeadingSegment,
|
|
163
|
+
bold: DefaultBoldSegment,
|
|
164
|
+
italic: DefaultItalicSegment,
|
|
165
|
+
strikethrough: DefaultStrikethroughSegment,
|
|
166
|
+
code: DefaultCodeSegment,
|
|
167
|
+
codeBlock: DefaultCodeBlockSegment,
|
|
168
|
+
link: DefaultLinkSegment,
|
|
169
|
+
linkUrl: DefaultLinkUrlSegment,
|
|
170
|
+
image: DefaultImageSegment,
|
|
171
|
+
quote: DefaultQuoteSegment,
|
|
172
|
+
quoteMarker: DefaultQuoteMarkerSegment,
|
|
173
|
+
listMarker: DefaultListMarkerSegment,
|
|
174
|
+
horizontalRule: DefaultHorizontalRuleSegment,
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=markdownSegmentDefaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownSegmentDefaults.js","sourceRoot":"","sources":["../src/markdownSegmentDefaults.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAMpC,8EAA8E;AAC9E,yBAAyB;AACzB,8EAA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C,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAEtD,sDAAsD;AACtD,MAAM,CAAC,MAAM,yBAAyB,GAAG,kBAAkB,CAAC;AAE5D,8DAA8D;AAC9D,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAE1D,wDAAwD;AACxD,MAAM,CAAC,MAAM,wBAAwB,GAAG,kBAAkB,CAAC;AAE3D,0EAA0E;AAC1E,MAAM,CAAC,MAAM,4BAA4B,GAAG,kBAAkB,CAAC;AAE/D;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAA6E;IACnH,IAAI,EAAE,cAAc;IACpB,SAAS,EAAE,uBAAuB;IAClC,OAAO,EAAE,qBAAqB;IAC9B,IAAI,EAAE,kBAAkB;IACxB,MAAM,EAAE,oBAAoB;IAC5B,aAAa,EAAE,2BAA2B;IAC1C,IAAI,EAAE,kBAAkB;IACxB,SAAS,EAAE,uBAAuB;IAClC,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,qBAAqB;IAC9B,KAAK,EAAE,mBAAmB;IAC1B,KAAK,EAAE,mBAAmB;IAC1B,WAAW,EAAE,yBAAyB;IACtC,UAAU,EAAE,wBAAwB;IACpC,cAAc,EAAE,4BAA4B;CAC5C,CAAC","sourcesContent":["import * as React from 'react';\nimport { Text } from 'react-native';\nimport type { TextStyle } from 'react-native';\n\nimport type { HighlightSegmentType } from './markdownHighlight.types';\nimport type { SegmentComponentProps } from './markdownSegment.types';\n\n// ---------------------------------------------------------------------------\n// Default styling values\n// ---------------------------------------------------------------------------\n\nconst COLOR_TEXT = '#1f1f1f';\nconst COLOR_DELIMITER = '#a0a0a0';\nconst COLOR_CODE = '#c7254e';\nconst COLOR_CODE_BG = '#f9f2f4';\nconst COLOR_LINK = '#2d5eff';\nconst COLOR_LINK_URL = '#8a8a8a';\nconst COLOR_IMAGE = '#2d5eff';\nconst COLOR_QUOTE = '#6a737d';\nconst COLOR_QUOTE_MARKER = '#a0a0a0';\nconst COLOR_LIST_MARKER = '#2d5eff';\nconst COLOR_HORIZONTAL_RULE = '#a0a0a0';\n\nconst FONT_SIZE = 16;\nconst FONT_SIZE_HEADING = Math.round(FONT_SIZE * 1.75);\nconst FONT_SIZE_CODE = Math.round(FONT_SIZE * 0.875);\nconst LINE_HEIGHT = computeLineHeight(FONT_SIZE);\nconst LINE_HEIGHT_CODE = computeLineHeight(FONT_SIZE_CODE);\n\nfunction computeLineHeight(fontSize: number): number {\n\treturn Math.ceil(fontSize * 1.5);\n}\n\nfunction getHeadingFontSize(level: number): number {\n\tif (level < 1 || level > 6) return FONT_SIZE;\n\tconst t = (level - 1) / 5;\n\treturn Math.round(FONT_SIZE_HEADING + t * (FONT_SIZE - FONT_SIZE_HEADING));\n}\n\nfunction getHeadingMetrics(meta?: Record<string, string>) {\n\tconst level = Number.parseInt(meta?.headingLevel ?? '1', 10);\n\tconst fontSize = getHeadingFontSize(Number.isNaN(level) ? 1 : level);\n\treturn {\n\t\tfontSize,\n\t\tlineHeight: computeLineHeight(fontSize),\n\t};\n}\n\nexport function getDefaultSegmentStyle(type: HighlightSegmentType, meta?: Record<string, string>): TextStyle {\n\tconst style: TextStyle = {\n\t\tcolor: COLOR_TEXT,\n\t\tfontSize: FONT_SIZE,\n\t\tlineHeight: LINE_HEIGHT,\n\t\tincludeFontPadding: false,\n\t};\n\n\tswitch (type) {\n\t\tcase 'delimiter':\n\t\t\tstyle.color = COLOR_DELIMITER;\n\t\t\tbreak;\n\t\tcase 'heading':\n\t\t\tstyle.fontWeight = 'bold';\n\t\t\tbreak;\n\t\tcase 'bold':\n\t\t\tstyle.fontWeight = 'bold';\n\t\t\tbreak;\n\t\tcase 'italic':\n\t\t\tstyle.fontStyle = 'italic';\n\t\t\tbreak;\n\t\tcase 'strikethrough':\n\t\t\tstyle.textDecorationLine = 'line-through';\n\t\t\tbreak;\n\t\tcase 'code':\n\t\t\tstyle.color = COLOR_CODE;\n\t\t\tstyle.backgroundColor = COLOR_CODE_BG;\n\t\t\tstyle.fontFamily = 'Courier';\n\t\t\tstyle.fontSize = FONT_SIZE_CODE;\n\t\t\tstyle.lineHeight = LINE_HEIGHT_CODE;\n\t\t\tbreak;\n\t\tcase 'codeBlock':\n\t\t\tstyle.color = COLOR_CODE;\n\t\t\tstyle.fontFamily = 'Courier';\n\t\t\tstyle.fontSize = FONT_SIZE_CODE;\n\t\t\tstyle.lineHeight = LINE_HEIGHT_CODE;\n\t\t\tbreak;\n\t\tcase 'link':\n\t\t\tstyle.color = COLOR_LINK;\n\t\t\tbreak;\n\t\tcase 'linkUrl':\n\t\t\tstyle.color = COLOR_LINK_URL;\n\t\t\tbreak;\n\t\tcase 'image':\n\t\t\tstyle.color = COLOR_IMAGE;\n\t\t\tbreak;\n\t\tcase 'quote':\n\t\t\tstyle.color = COLOR_QUOTE;\n\t\t\tbreak;\n\t\tcase 'quoteMarker':\n\t\t\tstyle.color = COLOR_QUOTE_MARKER;\n\t\t\tbreak;\n\t\tcase 'listMarker':\n\t\t\tstyle.color = COLOR_LIST_MARKER;\n\t\t\tstyle.fontWeight = 'bold';\n\t\t\tbreak;\n\t\tcase 'horizontalRule':\n\t\t\tstyle.color = COLOR_HORIZONTAL_RULE;\n\t\t\tstyle.letterSpacing = 4;\n\t\t\tstyle.textAlign = 'center';\n\t\t\tbreak;\n\t\tcase 'text':\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\n\tconst lineContext = meta?.lineContext;\n\tif (lineContext === 'heading') {\n\t\tconst { fontSize, lineHeight } = getHeadingMetrics(meta);\n\t\tstyle.fontSize = fontSize;\n\t\tstyle.lineHeight = lineHeight;\n\t\tstyle.fontWeight = 'bold';\n\t}\n\n\tif (lineContext === 'quote' && (type === 'text' || type === 'bold' || type === 'italic' || type === 'strikethrough')) {\n\t\tstyle.color = COLOR_QUOTE;\n\t}\n\n\tif (lineContext === 'codeFence' && type === 'delimiter') {\n\t\tstyle.fontSize = FONT_SIZE_CODE;\n\t\tstyle.lineHeight = LINE_HEIGHT_CODE;\n\t}\n\n\treturn style;\n}\n\n// ---------------------------------------------------------------------------\n// Default components\n// ---------------------------------------------------------------------------\n\n/** Default renderer - a plain Text with the default style for the segment type. */\nfunction DefaultTextSegment({ type, meta, children }: SegmentComponentProps) {\n\treturn <Text style={getDefaultSegmentStyle(type, meta)}>{children}</Text>;\n}\n\nexport const DefaultSegment = DefaultTextSegment;\n\n/** Default bold - renders bold text. */\nexport const DefaultBoldSegment = DefaultTextSegment;\n\n/** Default heading - renders heading text. */\nexport const DefaultHeadingSegment = DefaultTextSegment;\n\n/** Default italic - renders italic text. */\nexport const DefaultItalicSegment = DefaultTextSegment;\n\n/** Default strikethrough - renders strikethrough text. */\nexport const DefaultStrikethroughSegment = DefaultTextSegment;\n\n/** Default inline code - renders code text. */\nexport const DefaultCodeSegment = DefaultTextSegment;\n\n/** Default code block - renders code block content. */\nexport const DefaultCodeBlockSegment = DefaultTextSegment;\n\n/** Default link label - renders link text. */\nexport const DefaultLinkSegment = DefaultTextSegment;\n\n/** Default link URL - renders link URL text. */\nexport const DefaultLinkUrlSegment = DefaultTextSegment;\n\n/** Default image - renders image markdown text. */\nexport const DefaultImageSegment = DefaultTextSegment;\n\n/** Default blockquote - renders quote text. */\nexport const DefaultQuoteSegment = DefaultTextSegment;\n\n/** Default quote marker - renders the > character. */\nexport const DefaultQuoteMarkerSegment = DefaultTextSegment;\n\n/** Default delimiter - renders markdown syntax characters. */\nexport const DefaultDelimiterSegment = DefaultTextSegment;\n\n/** Default list marker - renders list bullet/number. */\nexport const DefaultListMarkerSegment = DefaultTextSegment;\n\n/** Default horizontal rule - renders the rule markers (---, ***, ___). */\nexport const DefaultHorizontalRuleSegment = DefaultTextSegment;\n\n/**\n * Complete map of default segment components.\n * Used as fallback when no custom component is provided for a type.\n */\nexport const DEFAULT_SEGMENT_COMPONENTS: Record<HighlightSegmentType, React.ComponentType<SegmentComponentProps>> = {\n\ttext: DefaultSegment,\n\tdelimiter: DefaultDelimiterSegment,\n\theading: DefaultHeadingSegment,\n\tbold: DefaultBoldSegment,\n\titalic: DefaultItalicSegment,\n\tstrikethrough: DefaultStrikethroughSegment,\n\tcode: DefaultCodeSegment,\n\tcodeBlock: DefaultCodeBlockSegment,\n\tlink: DefaultLinkSegment,\n\tlinkUrl: DefaultLinkUrlSegment,\n\timage: DefaultImageSegment,\n\tquote: DefaultQuoteSegment,\n\tquoteMarker: DefaultQuoteMarkerSegment,\n\tlistMarker: DefaultListMarkerSegment,\n\thorizontalRule: DefaultHorizontalRuleSegment,\n};\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level helpers shared by the markdown parser and the syntax highlighter.
|
|
3
|
+
*
|
|
4
|
+
* These utilities deal with escape sequences, token scanning, and
|
|
5
|
+
* image-source extraction — concerns common to both modules.
|
|
6
|
+
*/
|
|
7
|
+
import type { MarkdownToolbarAction } from './markdownCore.types';
|
|
8
|
+
/**
|
|
9
|
+
* Scans `input` for the first occurrence of `token` starting at `startIndex`,
|
|
10
|
+
* skipping any occurrence preceded by an odd number of backslashes.
|
|
11
|
+
*
|
|
12
|
+
* @returns The index of the token, or `-1` if not found.
|
|
13
|
+
*/
|
|
14
|
+
export declare function findUnescapedToken(input: string, token: string, startIndex: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* Returns `true` when the character at `index` is preceded by an
|
|
17
|
+
* odd number of backslashes (i.e. it is escaped).
|
|
18
|
+
*/
|
|
19
|
+
export declare function isEscaped(value: string, index: number): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Strips markdown escape backslashes from `value`.
|
|
22
|
+
* E.g. `"\\*hello\\*"` → `"*hello*"`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function unescapeMarkdown(value: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Parses the raw content inside `(…)` of an image markdown.
|
|
27
|
+
*
|
|
28
|
+
* Supports:
|
|
29
|
+
* - `url` → `{ src: "url" }`
|
|
30
|
+
* - `url "title"` or `url 'title'` → `{ src: "url", title: "title" }`
|
|
31
|
+
*
|
|
32
|
+
* @param raw - The string between the parentheses.
|
|
33
|
+
* @param options.unescapeSrc - Whether to unescape the source URL (default `true`).
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseImageSourceAndTitle(raw: string, options?: {
|
|
36
|
+
unescapeSrc?: boolean;
|
|
37
|
+
}): {
|
|
38
|
+
src: string;
|
|
39
|
+
title?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Checks whether a markdown feature is enabled based on the provided features list.
|
|
43
|
+
* If `features` is `undefined`, all features are considered enabled (backward compatible).
|
|
44
|
+
*
|
|
45
|
+
* Heading features (`heading`, `heading1`–`heading6`) are grouped: if any heading
|
|
46
|
+
* feature is present the `'heading'` feature is considered enabled.
|
|
47
|
+
*/
|
|
48
|
+
export type MarkdownFeature = 'bold' | 'italic' | 'strikethrough' | 'code' | 'codeBlock' | 'heading' | 'quote' | 'unorderedList' | 'orderedList' | 'divider' | 'image';
|
|
49
|
+
export declare function isMarkdownFeatureEnabled(features: MarkdownToolbarAction[] | undefined, feature: MarkdownFeature): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Checks whether a specific heading level is enabled.
|
|
52
|
+
*
|
|
53
|
+
* - If `features` is `undefined` → all levels enabled.
|
|
54
|
+
* - If `features` contains `'heading'` (generic) → all levels enabled.
|
|
55
|
+
* - Otherwise only the explicitly listed levels (`'heading1'`…`'heading6'`) are enabled.
|
|
56
|
+
*/
|
|
57
|
+
export declare function isHeadingLevelEnabled(features: MarkdownToolbarAction[] | undefined, level: number): boolean;
|
|
58
|
+
//# sourceMappingURL=markdownSyntaxUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownSyntaxUtils.d.ts","sourceRoot":"","sources":["../src/markdownSyntaxUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAKlE;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAe3F;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAM/D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GACtC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAcjC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,QAAQ,GACR,eAAe,GACf,MAAM,GACN,WAAW,GACX,SAAS,GACT,OAAO,GACP,eAAe,GACf,aAAa,GACb,SAAS,GACT,OAAO,CAAC;AAEZ,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,qBAAqB,EAAE,GAAG,SAAS,EAC7C,OAAO,EAAE,eAAe,GACvB,OAAO,CAeT;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,qBAAqB,EAAE,GAAG,SAAS,EAC7C,KAAK,EAAE,MAAM,GACZ,OAAO,CAIT"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level helpers shared by the markdown parser and the syntax highlighter.
|
|
3
|
+
*
|
|
4
|
+
* These utilities deal with escape sequences, token scanning, and
|
|
5
|
+
* image-source extraction — concerns common to both modules.
|
|
6
|
+
*/
|
|
7
|
+
/** Matches a backslash followed by a markdown-special character. */
|
|
8
|
+
const ESCAPED_MARKDOWN_PATTERN = /\\([\\`*_~[\]()#+.!>{}-])/g;
|
|
9
|
+
/**
|
|
10
|
+
* Scans `input` for the first occurrence of `token` starting at `startIndex`,
|
|
11
|
+
* skipping any occurrence preceded by an odd number of backslashes.
|
|
12
|
+
*
|
|
13
|
+
* @returns The index of the token, or `-1` if not found.
|
|
14
|
+
*/
|
|
15
|
+
export function findUnescapedToken(input, token, startIndex) {
|
|
16
|
+
if (token.length === 0) {
|
|
17
|
+
return -1;
|
|
18
|
+
}
|
|
19
|
+
for (let index = startIndex; index <= input.length - token.length; index += 1) {
|
|
20
|
+
if (input.slice(index, index + token.length) !== token) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (!isEscaped(input, index)) {
|
|
24
|
+
return index;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return -1;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns `true` when the character at `index` is preceded by an
|
|
31
|
+
* odd number of backslashes (i.e. it is escaped).
|
|
32
|
+
*/
|
|
33
|
+
export function isEscaped(value, index) {
|
|
34
|
+
let backslashes = 0;
|
|
35
|
+
for (let cursor = index - 1; cursor >= 0 && value[cursor] === '\\'; cursor -= 1) {
|
|
36
|
+
backslashes += 1;
|
|
37
|
+
}
|
|
38
|
+
return backslashes % 2 === 1;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Strips markdown escape backslashes from `value`.
|
|
42
|
+
* E.g. `"\\*hello\\*"` → `"*hello*"`.
|
|
43
|
+
*/
|
|
44
|
+
export function unescapeMarkdown(value) {
|
|
45
|
+
return value.replace(ESCAPED_MARKDOWN_PATTERN, '$1');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parses the raw content inside `(…)` of an image markdown.
|
|
49
|
+
*
|
|
50
|
+
* Supports:
|
|
51
|
+
* - `url` → `{ src: "url" }`
|
|
52
|
+
* - `url "title"` or `url 'title'` → `{ src: "url", title: "title" }`
|
|
53
|
+
*
|
|
54
|
+
* @param raw - The string between the parentheses.
|
|
55
|
+
* @param options.unescapeSrc - Whether to unescape the source URL (default `true`).
|
|
56
|
+
*/
|
|
57
|
+
export function parseImageSourceAndTitle(raw, options = {}) {
|
|
58
|
+
const { unescapeSrc = true } = options;
|
|
59
|
+
const normalizeSrc = (value) => (unescapeSrc ? unescapeMarkdown(value) : value);
|
|
60
|
+
const trimmed = raw.trim();
|
|
61
|
+
const titleMatch = trimmed.match(/^(.+?)\s+(?:"([^"]*)"|'([^']*)')$/);
|
|
62
|
+
if (titleMatch) {
|
|
63
|
+
return {
|
|
64
|
+
src: normalizeSrc(titleMatch[1].trim()),
|
|
65
|
+
title: titleMatch[2] ?? titleMatch[3],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return { src: normalizeSrc(trimmed) };
|
|
69
|
+
}
|
|
70
|
+
export function isMarkdownFeatureEnabled(features, feature) {
|
|
71
|
+
if (!features)
|
|
72
|
+
return true;
|
|
73
|
+
if (feature === 'heading') {
|
|
74
|
+
return features.some((a) => a === 'heading' ||
|
|
75
|
+
a === 'heading1' ||
|
|
76
|
+
a === 'heading2' ||
|
|
77
|
+
a === 'heading3' ||
|
|
78
|
+
a === 'heading4' ||
|
|
79
|
+
a === 'heading5' ||
|
|
80
|
+
a === 'heading6');
|
|
81
|
+
}
|
|
82
|
+
return features.includes(feature);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Checks whether a specific heading level is enabled.
|
|
86
|
+
*
|
|
87
|
+
* - If `features` is `undefined` → all levels enabled.
|
|
88
|
+
* - If `features` contains `'heading'` (generic) → all levels enabled.
|
|
89
|
+
* - Otherwise only the explicitly listed levels (`'heading1'`…`'heading6'`) are enabled.
|
|
90
|
+
*/
|
|
91
|
+
export function isHeadingLevelEnabled(features, level) {
|
|
92
|
+
if (!features)
|
|
93
|
+
return true;
|
|
94
|
+
if (features.includes('heading'))
|
|
95
|
+
return true;
|
|
96
|
+
return features.includes(`heading${level}`);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=markdownSyntaxUtils.js.map
|
|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qBAAqB,CACnC,QAA6C,EAC7C,KAAa;IAEb,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9C,OAAO,QAAQ,CAAC,QAAQ,CAAC,UAAU,KAAK,EAA2B,CAAC,CAAC;AACvE,CAAC","sourcesContent":["/**\n * Low-level helpers shared by the markdown parser and the syntax highlighter.\n *\n * These utilities deal with escape sequences, token scanning, and\n * image-source extraction — concerns common to both modules.\n */\n\nimport type { MarkdownToolbarAction } from './markdownCore.types';\n\n/** Matches a backslash followed by a markdown-special character. */\nconst ESCAPED_MARKDOWN_PATTERN = /\\\\([\\\\`*_~[\\]()#+.!>{}-])/g;\n\n/**\n * Scans `input` for the first occurrence of `token` starting at `startIndex`,\n * skipping any occurrence preceded by an odd number of backslashes.\n *\n * @returns The index of the token, or `-1` if not found.\n */\nexport function findUnescapedToken(input: string, token: string, startIndex: number): number {\n if (token.length === 0) {\n return -1;\n }\n\n for (let index = startIndex; index <= input.length - token.length; index += 1) {\n if (input.slice(index, index + token.length) !== token) {\n continue;\n }\n if (!isEscaped(input, index)) {\n return index;\n }\n }\n\n return -1;\n}\n\n/**\n * Returns `true` when the character at `index` is preceded by an\n * odd number of backslashes (i.e. it is escaped).\n */\nexport function isEscaped(value: string, index: number): boolean {\n let backslashes = 0;\n for (let cursor = index - 1; cursor >= 0 && value[cursor] === '\\\\'; cursor -= 1) {\n backslashes += 1;\n }\n return backslashes % 2 === 1;\n}\n\n/**\n * Strips markdown escape backslashes from `value`.\n * E.g. `\"\\\\*hello\\\\*\"` → `\"*hello*\"`.\n */\nexport function unescapeMarkdown(value: string): string {\n return value.replace(ESCAPED_MARKDOWN_PATTERN, '$1');\n}\n\n/**\n * Parses the raw content inside `(…)` of an image markdown.\n *\n * Supports:\n * - `url` → `{ src: \"url\" }`\n * - `url \"title\"` or `url 'title'` → `{ src: \"url\", title: \"title\" }`\n *\n * @param raw - The string between the parentheses.\n * @param options.unescapeSrc - Whether to unescape the source URL (default `true`).\n */\nexport function parseImageSourceAndTitle(\n raw: string,\n options: { unescapeSrc?: boolean } = {}\n): { src: string; title?: string } {\n const { unescapeSrc = true } = options;\n const normalizeSrc = (value: string) => (unescapeSrc ? unescapeMarkdown(value) : value);\n const trimmed = raw.trim();\n const titleMatch = trimmed.match(/^(.+?)\\s+(?:\"([^\"]*)\"|'([^']*)')$/);\n\n if (titleMatch) {\n return {\n src: normalizeSrc(titleMatch[1].trim()),\n title: titleMatch[2] ?? titleMatch[3],\n };\n }\n\n return { src: normalizeSrc(trimmed) };\n}\n\n/**\n * Checks whether a markdown feature is enabled based on the provided features list.\n * If `features` is `undefined`, all features are considered enabled (backward compatible).\n *\n * Heading features (`heading`, `heading1`–`heading6`) are grouped: if any heading\n * feature is present the `'heading'` feature is considered enabled.\n */\nexport type MarkdownFeature =\n | 'bold'\n | 'italic'\n | 'strikethrough'\n | 'code'\n | 'codeBlock'\n | 'heading'\n | 'quote'\n | 'unorderedList'\n | 'orderedList'\n | 'divider'\n | 'image';\n\nexport function isMarkdownFeatureEnabled(\n features: MarkdownToolbarAction[] | undefined,\n feature: MarkdownFeature,\n): boolean {\n if (!features) return true;\n if (feature === 'heading') {\n return features.some(\n (a) =>\n a === 'heading' ||\n a === 'heading1' ||\n a === 'heading2' ||\n a === 'heading3' ||\n a === 'heading4' ||\n a === 'heading5' ||\n a === 'heading6',\n );\n }\n return features.includes(feature as MarkdownToolbarAction);\n}\n\n/**\n * Checks whether a specific heading level is enabled.\n *\n * - If `features` is `undefined` → all levels enabled.\n * - If `features` contains `'heading'` (generic) → all levels enabled.\n * - Otherwise only the explicitly listed levels (`'heading1'`…`'heading6'`) are enabled.\n */\nexport function isHeadingLevelEnabled(\n features: MarkdownToolbarAction[] | undefined,\n level: number,\n): boolean {\n if (!features) return true;\n if (features.includes('heading')) return true;\n return features.includes(`heading${level}` as MarkdownToolbarAction);\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MarkdownInlineToolbarAction, MarkdownSelection, MarkdownToolbarAction, MarkdownToolbarActionResult } from './markdownCore.types';
|
|
2
|
+
export declare const DEFAULT_MARKDOWN_FEATURES: MarkdownToolbarAction[];
|
|
3
|
+
/** Parameters accepted by {@link applyMarkdownToolbarAction}. */
|
|
4
|
+
type ApplyMarkdownToolbarActionParams = {
|
|
5
|
+
action: MarkdownToolbarAction;
|
|
6
|
+
text: string;
|
|
7
|
+
selection: MarkdownSelection;
|
|
8
|
+
activeInlineActions?: MarkdownInlineToolbarAction[];
|
|
9
|
+
};
|
|
10
|
+
export declare function applyMarkdownToolbarAction({ action, text, selection, activeInlineActions, }: ApplyMarkdownToolbarActionParams): MarkdownToolbarActionResult;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=markdownToolbarActions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownToolbarActions.d.ts","sourceRoot":"","sources":["../src/markdownToolbarActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC5B,MAAM,sBAAsB,CAAC;AAE9B,eAAO,MAAM,yBAAyB,EAAE,qBAAqB,EAiB5D,CAAC;AASF,iEAAiE;AACjE,KAAK,gCAAgC,GAAG;IACtC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,iBAAiB,CAAC;IAC7B,mBAAmB,CAAC,EAAE,2BAA2B,EAAE,CAAC;CACrD,CAAC;AAEF,wBAAgB,0BAA0B,CAAC,EACzC,MAAM,EACN,IAAI,EACJ,SAAS,EACT,mBAAwB,GACzB,EAAE,gCAAgC,GAAG,2BAA2B,CAoBhE"}
|