{"id":24874651,"url":"https://github.com/dirheimerb/markdown-preview","last_synced_at":"2025-03-27T02:15:41.523Z","repository":{"id":183038745,"uuid":"669335494","full_name":"dirheimerb/markdown-preview","owner":"dirheimerb","description":null,"archived":false,"fork":false,"pushed_at":"2023-07-22T14:15:49.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T07:28:58.903Z","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/dirheimerb.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}},"created_at":"2023-07-22T00:53:18.000Z","updated_at":"2023-07-22T00:53:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"14705f0d-dcce-45f5-a1b2-21a262e4a63e","html_url":"https://github.com/dirheimerb/markdown-preview","commit_stats":null,"previous_names":["dirheimerb/markdown-preview"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirheimerb%2Fmarkdown-preview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirheimerb%2Fmarkdown-preview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirheimerb%2Fmarkdown-preview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirheimerb%2Fmarkdown-preview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dirheimerb","download_url":"https://codeload.github.com/dirheimerb/markdown-preview/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245767360,"owners_count":20668826,"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":"2025-02-01T07:28:05.770Z","updated_at":"2025-03-27T02:15:41.503Z","avatar_url":"https://github.com/dirheimerb.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Markdown Editor and Previewer\n\nThis package provides a Markdown editor with a live preview feature for React applications. It allows users to write Markdown content and view its rendered HTML output in real-time. The editor also supports syntax highlighting for code blocks.\n\n## Installation\n\nTo use this package in your React project, you can install it using npm or yarn:\n\n```bash\nnpm install markdown-preview\n```\n\nor\n\n```bash\nyarn add markdown-preview\n```\n\n## Usage\n\nImport the necessary components and set up your React application as follows:\n\n```jsx\nimport React from 'react';\nimport MDProvider from \"markdown-preview/lib/context/MDProvider\";\nimport MD from \"markdown-preview/components/MD\";\nimport './globals.css';\n\nexport default function App() {   \n    return (\n        \u003cMDProvider\u003e\n            \u003cMD /\u003e\n        \u003c/MDProvider\u003e\n    );\n}\n```\n\nThe `App` component should wrap the editor inside the `MDProvider`, which sets up the context for handling Markdown content.\n\n## MD Component\n\nThe `MD` component provides the Markdown editor and live preview. It uses the `MarkdownContext` provided by `MDProvider` to manage the Markdown content.\n\n```jsx\nimport React from 'react';\nimport { Tab } from '@headlessui/react';\nimport clsx from 'clsx';\nimport { MarkdownContext } from 'markdown-preview/lib/context/MarkdownProvider';\n\nconst MDPreview = React.lazy(() =\u003e import('markdown-preview/components/MDPreview'));\n\nexport default function MD() { \n  const { markdown, handleMarkdownUpdate } =\n    React.useContext(MarkdownContext);\n\n  const handleSubmit = async (e: React.FormEvent\u003cHTMLFormElement\u003e) =\u003e {\n    e.preventDefault();\n    // Your logic for handling the Markdown content goes here\n  };\n\n  return (\n    // JSX code for the editor and preview components\n  );\n}\n```\n\n## MarkdownProvider\n\nThe `MarkdownProvider` component is used to set up the context for managing Markdown content.\n\n```jsx\nimport React from 'react';\nimport { MarkdownContextProps } from 'markdown-preview/lib/context/MarkdownProvider';\n\nexport const MarkdownContext = React.createContext\u003cMarkdownContextProps\u003e({\n  markdown: '',\n  html: '',\n  handleMarkdownUpdate: () =\u003e {}, // Provide a default function\n});\n\nexport default function MarkdownProvider({\n  children,\n  markdown,\n  html,\n  handleMarkdownUpdate,\n}: MarkdownProviderProps \u0026 MarkdownContextProps) {\n  return (\n    \u003cMarkdownContext.Provider value={{ markdown, html, handleMarkdownUpdate }}\u003e\n      {children}\n    \u003c/MarkdownContext.Provider\u003e\n  );\n}\n```\n\n## Custom Markdown Parser\n\nThis package uses the `remarkable` library for parsing Markdown and the `highlight.js` library for syntax highlighting in code blocks. The Markdown parser and syntax highlighter are configured in the `./lib/context/MarkdownParser.js` file.\n\n## Contributing\n\nIf you encounter any issues or have suggestions for improvement, feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/your-repo).\n\n## License\n\nThis package is licensed under the [MIT License](https://opensource.org/licenses/MIT). Feel free to use it in your projects.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirheimerb%2Fmarkdown-preview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdirheimerb%2Fmarkdown-preview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirheimerb%2Fmarkdown-preview/lists"}