{"id":17242755,"url":"https://github.com/imcuttle/live-markd","last_synced_at":"2025-04-14T03:25:30.018Z","repository":{"id":33209451,"uuid":"154851985","full_name":"imcuttle/live-markd","owner":"imcuttle","description":"📝Github Favorite Markdown preview with live rendering \u0026 location and highlight changed block.","archived":false,"fork":false,"pushed_at":"2023-01-24T06:27:17.000Z","size":3269,"stargazers_count":9,"open_issues_count":35,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T03:36:16.294Z","etag":null,"topics":["gfm","github","live","markdown","preview"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imcuttle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-26T15:02:21.000Z","updated_at":"2022-07-21T12:51:32.000Z","dependencies_parsed_at":"2023-02-13T18:31:01.877Z","dependency_job_id":null,"html_url":"https://github.com/imcuttle/live-markd","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Flive-markd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Flive-markd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Flive-markd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Flive-markd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imcuttle","download_url":"https://codeload.github.com/imcuttle/live-markd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248814628,"owners_count":21165796,"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":["gfm","github","live","markdown","preview"],"created_at":"2024-10-15T06:13:59.362Z","updated_at":"2025-04-14T03:25:29.980Z","avatar_url":"https://github.com/imcuttle.png","language":"JavaScript","readme":"# live-markd\n\n[![Build status](https://img.shields.io/travis/imcuttle/live-markd/master.svg?style=flat-square)](https://travis-ci.org/imcuttle/live-markd)\n[![Test coverage](https://img.shields.io/codecov/c/github/imcuttle/live-markd.svg?style=flat-square)](https://codecov.io/github/imcuttle/live-markd?branch=master)\n[![NPM version](https://img.shields.io/npm/v/live-markd.svg?style=flat-square)](https://www.npmjs.com/package/live-markd)\n[![NPM Downloads](https://img.shields.io/npm/dm/live-markd.svg?style=flat-square\u0026maxAge=43200)](https://www.npmjs.com/package/live-markd)\n[![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://prettier.io/)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org)\n\n\u003e 📝Github Favorite Markdown([gfm](https://github.github.com/gfm/)) preview with live rendering \u0026 location and highlight changed block.\n\n![](https://i.loli.net/2018/10/28/5bd58a95c6b7d.gif)\n\n## Table of Contents\n\n\u003c!-- toc --\u003e\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [API](#api)\n- [How it works?](#how-it-works)\n- [Related](#related)\n- [Contributing](#contributing)\n- [Authors](#authors)\n- [License](#license)\n\n\u003c!-- tocstop --\u003e\n\n## Installation\n\n```bash\nnpm install live-markd -g\n\nlive-markd .\n```\n\n## Usage\n\n#### Standalone\n\n```javascript\nconst liveMarkd = require('live-markd')\n\n// Returns express app instance listened port 8080\nconst app = liveMarkd('path/to/dir', {\n  port: 8080,\n  baseUrl: '/www'\n})\n```\n\n#### Use with express\n\n```javascript\nconst app = require('express')()\nconst liveMarkd = require('live-markd')\n\nconst middleware = liveMarkd('path/to/dir', {\n  heartBeatDelay: 4 * 1000, // 4s\n  gssOptions: {}\n})\n\napp.use(middleware)\n// or\napp.use('/base-url', middleware)\n```\n\n#### CLI\n\n```\nnpm i live-markd -g\nlive-markd \u003cpath\u003e\n```\n\n## API\n\n### `liveMarkd(root [, options])`\n\n#### `root`\n\nThe markdown files' root folder or exact file.\n\n- Type: `string`\n\n#### Options\n\n##### `port`\n\nThe server's port\n\n- Type: `number`\n\n##### `baseUrl`\n\nThe server's baseUrl (**only works on `port` is assigned**)\n\n- Type: `string`\n\n##### `heartBeatDelay`\n\nThe heartbeat detection's interval millisecond\n\n- Type: `number`\n- Default: `10 * 1000`\n\n##### `gssOptions`\n\n**Except `port`, `basePath`, rest options extends [github-similar-server](https://github.com/imcuttle/github-similar-server)**\n\n###### `templateParameters`\n\n**NOTE:** Expect [preset parameters](https://github.com/imcuttle/github-similar-server/blob/master/README.md#about-markdowntemplate) from github-similar-server\n\nlive-markd has injected follow parameters\n\n| name      | description                                         |\n| --------- | --------------------------------------------------- |\n| `baseUrl` | the base url from `app.use('/baseUrl', lived(...))` |\n\n###### `markdownTemplate`\n\nThe path of markdown's template, It's useful for customizing your suitable markdown style.\n\n- Type: `string`\n- Default: [`./dist/template.html`](./dist/template.html)\n\n## How it works?\n\n### Data Flow\n\n```text\nFs Watcher -\u003e Event Stream -\u003e Client\n                   |\n   markdown diff   |   heartbeat \u0026 data\n                   |\n      [ Server ]   |   [ Browser ]\n```\n\n### Markdown Diff\n\nI use [remark](https://github.com/remarkjs/remark) for treating markdown text as markdown abstract syntax tree(MDAST),\nthen new MDAST comparing with old one.\n\nFor example\n\n- `old.md`\n\n```\n# hi\nworld\n```\n\n- `new.md`\n\n```\n# hi\nworld!\n```\n\n- [MDAST](https://github.com/syntax-tree/mdast) of `old.md`\n\n```javascript\n{\n  type: 'root',\n  children: [\n    {\n      type: 'heading',\n      depth: 1,\n      children: [{\n        type: 'paragraph',\n        children: [{ type: 'text', value: 'world' }]\n      }]\n    }\n  ]\n}\n```\n\n- [MDAST](https://github.com/syntax-tree/mdast) of `new.md`\n\n```javascript\n{\n  type: 'root',\n  children: [\n    {\n      type: 'heading',\n      depth: 1,\n      children: [{\n        type: 'paragraph',\n        // This node is different with `old.md`\n        children: [{ type: 'text', value: 'world!' }]\n      }]\n    }\n  ]\n}\n```\n\n## Related\n\n- [github-similar-server](https://github.com/imcuttle/github-similar-server) - A github similar static server with a markdown renderer.\n- [detect-one-changed](https://github.com/imcuttle/detect-one-changed) - Detect first changed html and markdown between old text and new one.\n\n## Contributing\n\n- Fork it!\n- Create your new branch:  \n  `git checkout -b feature-new` or `git checkout -b fix-which-bug`\n- Start your magic work now\n- Make sure npm test passes\n- Commit your changes:  \n  `git commit -am 'feat: some description (close #123)'` or `git commit -am 'fix: some description (fix #123)'`\n- Push to the branch: `git push`\n- Submit a pull request :)\n\n## Authors\n\nThis library is written and maintained by imcuttle, \u003ca href=\"mailto:moyuyc95@gmail.com\"\u003emoyuyc95@gmail.com\u003c/a\u003e.\n\n## License\n\nMIT - [imcuttle](https://github.com/imcuttle) 🐟\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Flive-markd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimcuttle%2Flive-markd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Flive-markd/lists"}