Skip to content

Commit

Permalink
Merge pull request #295 from vordgi/rd-294
Browse files Browse the repository at this point in the history
rd-294 improve code parsing
  • Loading branch information
vordgi authored Oct 13, 2024
2 parents 66ed034 + 1330574 commit 972a9fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/robindoc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "robindoc",
"version": "1.2.0",
"version": "1.2.1",
"description": "",
"main": "./lib/index.js",
"scripts": {
Expand Down
11 changes: 9 additions & 2 deletions packages/robindoc/src/components/elements/article/document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ export const Document: React.FC<ContentProps> = ({
);
case "paragraph":
if (subtree) return token.tokens ? <DocumentToken token={token.tokens} /> : token.raw;
if (
token.tokens?.some((t) => t.type === "html") &&
token.tokens?.every((t) => t.type === "html" || t.raw === "\n")
) {
return <DocumentToken token={{ ...token, type: "html" }} />;
}

return <Paragraph>{token.tokens ? <DocumentToken token={token.tokens} /> : token.raw}</Paragraph>;
case "strong":
Expand Down Expand Up @@ -257,7 +263,7 @@ export const Document: React.FC<ContentProps> = ({
if (isTaskList) {
const ListComponent = token.ordered ? TaskOrderedList : TaskUnorderedList;
return (
<ListComponent>
<ListComponent start={token.start}>
{token.items.map((elem: Tokens.ListItem, index: number) => (
<TaskListItem key={elem.raw + index} defaultChecked={elem.checked}>
{elem.tokens ? <DocumentToken token={elem.tokens} /> : elem.raw}
Expand All @@ -269,7 +275,7 @@ export const Document: React.FC<ContentProps> = ({

const ListComponent = token.ordered ? OrderedList : UnorderedList;
return (
<ListComponent>
<ListComponent start={token.start}>
{token.items.map((elem: Tokens.ListItem, index: number) => (
<ListItem key={elem.raw + index}>
{elem.tokens ? <DocumentToken token={elem.tokens} /> : elem.raw}
Expand All @@ -279,6 +285,7 @@ export const Document: React.FC<ContentProps> = ({
);
case "html":
const text = token.raw.trim();
// console.log("html", token);

if (text.startsWith("<!---robin") && text.endsWith("-->")) {
const selfClosed = text.endsWith("/-->");
Expand Down
2 changes: 1 addition & 1 deletion packages/robindoc/src/components/elements/article/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export const parseCodeLang = (raw: string) => {
let lang: string = raw;

const match = raw.match(/[a-z]+=("[^"]+"|'[^']+'|[^ ]+)|[a-z]+/g);
const [language, ...modifiers] = match as string[];
if (Array.isArray(match)) {
const [language, ...modifiers] = match as string[];
lang = language;
configuration = modifiers.reduce<{ [key: string]: string | boolean }>((acc, cur) => {
const [key, ...value] = cur.split("=");
Expand Down

0 comments on commit 972a9fa

Please sign in to comment.