{"id":16798156,"url":"https://github.com/kovsu/vite-plugin-markdown-test","last_synced_at":"2025-03-17T04:24:53.650Z","repository":{"id":135569203,"uuid":"550246478","full_name":"kovsu/vite-plugin-markdown-test","owner":"kovsu","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-12T13:52:48.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T14:15:28.782Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kovsu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-10-12T12:43:29.000Z","updated_at":"2022-11-21T13:29:39.000Z","dependencies_parsed_at":"2024-03-18T07:52:53.419Z","dependency_job_id":"8c6d874b-4d4a-48ce-a9e3-8101741b89f2","html_url":"https://github.com/kovsu/vite-plugin-markdown-test","commit_stats":null,"previous_names":["konvsuu/vite-plugin-markdown-test","kovsu/vite-plugin-markdown-test"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovsu%2Fvite-plugin-markdown-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovsu%2Fvite-plugin-markdown-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovsu%2Fvite-plugin-markdown-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovsu%2Fvite-plugin-markdown-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kovsu","download_url":"https://codeload.github.com/kovsu/vite-plugin-markdown-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243971886,"owners_count":20376905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T09:24:43.571Z","updated_at":"2025-03-17T04:24:53.622Z","avatar_url":"https://github.com/kovsu.png","language":"TypeScript","readme":"## Vite-plugin for markdown\n\n### core code\n```ts\nconst markdownRE = /\u003cvite-markdown file=\"(.*)\"\u003e\u003c\\/vite-markdown\u003e/g;\n\n...\n\nconst matches = Array.from(code.matchAll(markdownRE));\n\n...\n\ntry {\n  const data = fs\n    .readFileSync(resolve(dirname(id), match[1]), {\n      encoding: \"utf-8\",\n    })\n    .toString();\n  code = code.replaceAll(markdownRE, transformMarkdown(data));\n} catch {\n  code = code.replaceAll(markdownRE, \"\");\n}\n```\nFirst, get matching code.\n\nThen use **fs.readFileSync** get source file content, and use pkg [markdown-it](https://www.npmjs.com/package/markdown-it) to render it (make .md content to be like .html)\n\n```ts\nconst transformMarkdown = (mdText: string): string =\u003e {\n  return `\n    \u003csection class='article-content'\u003e\n      ${md.render(mdText)}\n    \u003c/section\u003e\n  `;\n};\n```\n\nIn the last, use function transformMarkdown's result to replace the component in vue.\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkovsu%2Fvite-plugin-markdown-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkovsu%2Fvite-plugin-markdown-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkovsu%2Fvite-plugin-markdown-test/lists"}