solid-markdown
Advanced tools
Comparing version 2.0.3 to 2.0.4
import { insert, createComponent, memo, effect, className, Dynamic, mergeProps as mergeProps$1, template } from 'solid-js/web'; | ||
import remarkParse from 'remark-parse'; | ||
import remarkRehype from 'remark-rehype'; | ||
import { mergeProps, createMemo, createRenderEffect, For, Switch, Match } from 'solid-js'; | ||
import { mergeProps, createMemo, createRenderEffect, For, Switch, Match, Show } from 'solid-js'; | ||
import { createStore, reconcile } from 'solid-js/store'; | ||
@@ -139,3 +139,14 @@ import { html, find, svg } from 'property-information'; | ||
get children() { | ||
return child.value; | ||
return createComponent(MarkdownText, { | ||
get context() { | ||
return props.context; | ||
}, | ||
get index() { | ||
return index(); | ||
}, | ||
node: child, | ||
get parent() { | ||
return props.node; | ||
} | ||
}); | ||
} | ||
@@ -146,2 +157,57 @@ })]; | ||
}); | ||
var MarkdownText = (props) => { | ||
const childProps = createMemo(() => { | ||
const context = { | ||
...props.context | ||
}; | ||
const options = context.options; | ||
const node = props.node; | ||
props.parent; | ||
const properties = {}; | ||
const position = node.position || { | ||
start: { | ||
line: null, | ||
column: null, | ||
offset: null | ||
}, | ||
end: { | ||
line: null, | ||
column: null, | ||
offset: null | ||
} | ||
}; | ||
const component = options.components && own.call(options.components, "text") ? options.components.text : null; | ||
const basic = typeof component === "string"; | ||
properties.key = ["text", position.start.line, position.start.column, props.index].join("-"); | ||
if (options.sourcePos) { | ||
properties["data-sourcepos"] = flattenPosition(position); | ||
} | ||
if (!basic && options.rawSourcePos) { | ||
properties.sourcePosition = node.position; | ||
} | ||
if (!basic) { | ||
properties.node = node; | ||
} | ||
return { | ||
properties, | ||
context, | ||
component | ||
}; | ||
}); | ||
return createComponent(Show, { | ||
get when() { | ||
return childProps().component; | ||
}, | ||
get fallback() { | ||
return props.node.value; | ||
}, | ||
get children() { | ||
return createComponent(Dynamic, mergeProps$1({ | ||
get component() { | ||
return childProps().component || "span"; | ||
} | ||
}, () => childProps().properties)); | ||
} | ||
}); | ||
}; | ||
var MarkdownNode = (props) => { | ||
@@ -148,0 +214,0 @@ const childProps = createMemo(() => { |
@@ -53,3 +53,3 @@ // src/index.tsx | ||
// src/renderer.tsx | ||
import { For, Match, Switch, createMemo } from "solid-js"; | ||
import { For, Match, Switch, createMemo, Show } from "solid-js"; | ||
import { svg } from "property-information"; | ||
@@ -121,3 +121,43 @@ import { Dynamic } from "solid-js/web"; | ||
parent={props.node} | ||
/></Match><Match when={child.type === "text" && child.value !== "\n"}>{child.value}</Match></Switch>}</For>; | ||
/></Match><Match when={child.type === "text" && child.value !== "\n"}><MarkdownText | ||
context={props.context} | ||
index={index()} | ||
node={child} | ||
parent={props.node} | ||
/></Match></Switch>}</For>; | ||
var MarkdownText = (props) => { | ||
const childProps = createMemo(() => { | ||
const context = { ...props.context }; | ||
const options = context.options; | ||
const node = props.node; | ||
const parent = props.parent; | ||
const properties = {}; | ||
const position = node.position || { | ||
start: { line: null, column: null, offset: null }, | ||
end: { line: null, column: null, offset: null } | ||
}; | ||
const component = options.components && own.call(options.components, "text") ? options.components.text : null; | ||
const basic = typeof component === "string"; | ||
properties.key = [ | ||
"text", | ||
position.start.line, | ||
position.start.column, | ||
props.index | ||
].join("-"); | ||
if (options.sourcePos) { | ||
properties["data-sourcepos"] = flattenPosition(position); | ||
} | ||
if (!basic && options.rawSourcePos) { | ||
properties.sourcePosition = node.position; | ||
} | ||
if (!basic) { | ||
properties.node = node; | ||
} | ||
return { properties, context, component }; | ||
}); | ||
return <Show when={childProps().component} fallback={props.node.value}><Dynamic | ||
component={childProps().component || "span"} | ||
{...childProps().properties} | ||
/></Show>; | ||
}; | ||
var MarkdownNode = (props) => { | ||
@@ -124,0 +164,0 @@ const childProps = createMemo(() => { |
@@ -1,5 +0,5 @@ | ||
import { JSX, Component } from 'solid-js'; | ||
import { Component, JSX } from 'solid-js'; | ||
import { PluggableList } from 'unified'; | ||
import { Position } from 'unist'; | ||
import { ElementContent, Element, Root } from 'hast'; | ||
import { ElementContent, Text, Element, Root } from 'hast'; | ||
@@ -71,3 +71,7 @@ interface SolidMarkdownProps { | ||
}; | ||
type Components = Partial<Omit<NormalComponents, keyof SpecialComponents>> & Partial<SpecialComponents>; | ||
type Components = Omit<Partial<Omit<NormalComponents, keyof SpecialComponents>> & Partial<SpecialComponents>, "text"> & { | ||
text?: Component<{ | ||
node: Text; | ||
}>; | ||
}; | ||
type Options$1 = { | ||
@@ -104,4 +108,5 @@ sourcePos: boolean; | ||
type SolidMarkdownOptions = CoreOptions & PluginOptions & LayoutOptions & Options & Options$1; | ||
type SolidMarkdownComponents = Options$1["components"]; | ||
declare const SolidMarkdown: Component<Partial<SolidMarkdownOptions>>; | ||
export { SolidMarkdown }; | ||
export { SolidMarkdown, type SolidMarkdownComponents, type SolidMarkdownOptions }; |
import { insert, createComponent, memo, effect, className, Dynamic, mergeProps as mergeProps$1, template } from 'solid-js/web'; | ||
import remarkParse from 'remark-parse'; | ||
import remarkRehype from 'remark-rehype'; | ||
import { mergeProps, createMemo, createRenderEffect, For, Switch, Match } from 'solid-js'; | ||
import { mergeProps, createMemo, createRenderEffect, For, Switch, Match, Show } from 'solid-js'; | ||
import { createStore, reconcile } from 'solid-js/store'; | ||
@@ -139,3 +139,14 @@ import { html, find, svg } from 'property-information'; | ||
get children() { | ||
return child.value; | ||
return createComponent(MarkdownText, { | ||
get context() { | ||
return props.context; | ||
}, | ||
get index() { | ||
return index(); | ||
}, | ||
node: child, | ||
get parent() { | ||
return props.node; | ||
} | ||
}); | ||
} | ||
@@ -146,2 +157,57 @@ })]; | ||
}); | ||
var MarkdownText = (props) => { | ||
const childProps = createMemo(() => { | ||
const context = { | ||
...props.context | ||
}; | ||
const options = context.options; | ||
const node = props.node; | ||
props.parent; | ||
const properties = {}; | ||
const position = node.position || { | ||
start: { | ||
line: null, | ||
column: null, | ||
offset: null | ||
}, | ||
end: { | ||
line: null, | ||
column: null, | ||
offset: null | ||
} | ||
}; | ||
const component = options.components && own.call(options.components, "text") ? options.components.text : null; | ||
const basic = typeof component === "string"; | ||
properties.key = ["text", position.start.line, position.start.column, props.index].join("-"); | ||
if (options.sourcePos) { | ||
properties["data-sourcepos"] = flattenPosition(position); | ||
} | ||
if (!basic && options.rawSourcePos) { | ||
properties.sourcePosition = node.position; | ||
} | ||
if (!basic) { | ||
properties.node = node; | ||
} | ||
return { | ||
properties, | ||
context, | ||
component | ||
}; | ||
}); | ||
return createComponent(Show, { | ||
get when() { | ||
return childProps().component; | ||
}, | ||
get fallback() { | ||
return props.node.value; | ||
}, | ||
get children() { | ||
return createComponent(Dynamic, mergeProps$1({ | ||
get component() { | ||
return childProps().component || "span"; | ||
} | ||
}, () => childProps().properties)); | ||
} | ||
}); | ||
}; | ||
var MarkdownNode = (props) => { | ||
@@ -148,0 +214,0 @@ const childProps = createMemo(() => { |
@@ -53,3 +53,3 @@ // src/index.tsx | ||
// src/renderer.tsx | ||
import { For, Match, Switch, createMemo } from "solid-js"; | ||
import { For, Match, Switch, createMemo, Show } from "solid-js"; | ||
import { svg } from "property-information"; | ||
@@ -121,3 +121,43 @@ import { Dynamic } from "solid-js/web"; | ||
parent={props.node} | ||
/></Match><Match when={child.type === "text" && child.value !== "\n"}>{child.value}</Match></Switch>}</For>; | ||
/></Match><Match when={child.type === "text" && child.value !== "\n"}><MarkdownText | ||
context={props.context} | ||
index={index()} | ||
node={child} | ||
parent={props.node} | ||
/></Match></Switch>}</For>; | ||
var MarkdownText = (props) => { | ||
const childProps = createMemo(() => { | ||
const context = { ...props.context }; | ||
const options = context.options; | ||
const node = props.node; | ||
const parent = props.parent; | ||
const properties = {}; | ||
const position = node.position || { | ||
start: { line: null, column: null, offset: null }, | ||
end: { line: null, column: null, offset: null } | ||
}; | ||
const component = options.components && own.call(options.components, "text") ? options.components.text : null; | ||
const basic = typeof component === "string"; | ||
properties.key = [ | ||
"text", | ||
position.start.line, | ||
position.start.column, | ||
props.index | ||
].join("-"); | ||
if (options.sourcePos) { | ||
properties["data-sourcepos"] = flattenPosition(position); | ||
} | ||
if (!basic && options.rawSourcePos) { | ||
properties.sourcePosition = node.position; | ||
} | ||
if (!basic) { | ||
properties.node = node; | ||
} | ||
return { properties, context, component }; | ||
}); | ||
return <Show when={childProps().component} fallback={props.node.value}><Dynamic | ||
component={childProps().component || "span"} | ||
{...childProps().properties} | ||
/></Show>; | ||
}; | ||
var MarkdownNode = (props) => { | ||
@@ -124,0 +164,0 @@ const childProps = createMemo(() => { |
{ | ||
"name": "solid-markdown", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Markdown renderer for solid-js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55366
1527