{"id":21461573,"url":"https://github.com/snowdreams1006/gitbook-plugin-diff","last_synced_at":"2025-09-01T12:15:33.392Z","repository":{"id":135331849,"uuid":"247244901","full_name":"snowdreams1006/gitbook-plugin-diff","owner":"snowdreams1006","description":"A gitbook plugin for showing the differences between the codes within markdown","archived":false,"fork":false,"pushed_at":"2024-08-15T06:43:19.000Z","size":1186,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-02T23:18:09.610Z","etag":null,"topics":["code","compare","diff","gitbook-plugin","gitbook-plugin-diff","jsdiff"],"latest_commit_sha":null,"homepage":"https://snowdreams1006.github.io/gitbook-plugin-diff/","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/snowdreams1006.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2020-03-14T09:09:38.000Z","updated_at":"2024-08-15T06:43:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"15f4d5ba-b778-4664-8344-3669e33908f7","html_url":"https://github.com/snowdreams1006/gitbook-plugin-diff","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/snowdreams1006/gitbook-plugin-diff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snowdreams1006%2Fgitbook-plugin-diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snowdreams1006%2Fgitbook-plugin-diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snowdreams1006%2Fgitbook-plugin-diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snowdreams1006%2Fgitbook-plugin-diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/snowdreams1006","download_url":"https://codeload.github.com/snowdreams1006/gitbook-plugin-diff/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snowdreams1006%2Fgitbook-plugin-diff/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265397504,"owners_count":23758443,"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":["code","compare","diff","gitbook-plugin","gitbook-plugin-diff","jsdiff"],"created_at":"2024-11-23T07:09:49.229Z","updated_at":"2025-07-15T03:30:24.149Z","avatar_url":"https://github.com/snowdreams1006.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Welcome to gitbook-plugin-diff 👋\n\n[![npm:version](https://img.shields.io/npm/v/gitbook-plugin-diff.svg)](https://www.npmjs.com/package/gitbook-plugin-diff)\n[![npm:download](https://img.shields.io/npm/dt/gitbook-plugin-diff.svg)](https://www.npmjs.com/package/gitbook-plugin-diff)\n[![npm:prerequisite](https://img.shields.io/badge/gitbook-*-blue.svg)](https://www.npmjs.com/package/gitbook-plugin-diff)\n[![github:documentation](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](https://github.com/snowdreams1006/gitbook-plugin-diff#readme)\n[![github:maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/snowdreams1006/gitbook-plugin-diff/graphs/commit-activity)\n[![npm:license](https://img.shields.io/npm/l/gitbook-plugin-diff.svg)](https://github.com/snowdreams1006/gitbook-plugin-diff/blob/master/LICENSE)\n[![github:snodreams1006](https://img.shields.io/badge/github-snowdreams1006-brightgreen.svg)](https://github.com/snowdreams1006)\n[![website:snodreams1006.tech](https://img.shields.io/badge/website-snowdreams1006.tech-brightgreen.svg)](https://snowdreams1006.tech/)\n[![微信公众号:雪之梦技术驿站-brightgreen.svg](https://img.shields.io/badge/%E5%BE%AE%E4%BF%A1%E5%85%AC%E4%BC%97%E5%8F%B7-%E9%9B%AA%E4%B9%8B%E6%A2%A6%E6%8A%80%E6%9C%AF%E9%A9%BF%E7%AB%99-brightgreen.svg)](https://snowdreams1006.github.io/snowdreams1006-wechat-public.jpeg)\n\n\u003e A gitbook plugin for showing the differences between the codes within markdown\n\n## Screenshot\n\n- usage\n\n````markdown\n{% diff method=\"diffJson\" %}\n```json\n{\n  \"name\": \"gitbook-plugin-simple-mind-map\",\n  \"version\": \"0.2.1\",\n  \"description\": \"A gitBook plugin for generating and exporting mind map within markdown\"\n}\n```\n```json\n{\n  \"name\": \"gitbook-plugin-diff\",\n  \"version\": \"0.2.1\",\n  \"description\": \"A gitbook plugin for showing the differences between the codes within markdown\"\n}\n```\n{% enddiff %}\n````\n\n- preview\n\n```diff\n{\n-   \"description\": \"A gitBook plugin for generating and exporting mind map within markdown\",\n-   \"name\": \"gitbook-plugin-simple-mind-map\",\n+   \"description\": \"A gitbook plugin for showing the differences between the codes within markdown\",\n+   \"name\": \"gitbook-plugin-diff\",\n    \"version\": \"0.2.1\"\n}\n```\n\n## Usage\n\n### Step #1 - Update `book.json` file\n\nIn you gitbook's `book.json` file, add `diff` to `plugins` list.\n\nHere is simplest example :\n\n```json\n{\n    \"plugins\": [\"diff\"]\n}\n```\n\nIn addition, the supported configuration options are as follows : \n\n```json\n\"gitbook\": {\n    \"properties\": {\n        \"type\": {\n            \"type\": \"string\",\n            \"title\": \"render type\",\n            \"required\": false,\n            \"default\": \"markdown\",\n            \"description\": \"some supported methods such as markdown or console or html\"\n        },\n        \"method\": {\n            \"type\": \"string\",\n            \"title\": \"jsdiff api method\",\n            \"required\": false,\n            \"default\": \"diffChars\",\n            \"description\": \"some supported methods such as diffChars or diffWords or diffWordsWithSpace or diffLines or diffTrimmedLines or diffSentences or diffJson or diffArrays\"\n        },\n        \"options\": {\n            \"type\": \"object\",\n            \"title\": \"jsdiff api options\",\n            \"required\": false,\n            \"description\": \"some methods may not support options\"\n        }\n    }\n}\n```\n\n### Step #2 - Use in markdown file\n\n`diff` support `method` and `options` for generating diff block code.\n\nHere is basic grammar in your markdown file :\n\n````\n{% diff %}\n```\nold code\n```\n```\nnew code\n```\n{% enddiff %}\n````\n\nAnd there are some examples :\n\n#### `Diff.diffChars(oldStr, newStr[, options])`\n\n\u003e diffs two blocks of text, comparing character by character.\n\n**Return**\n\nReturns a list of change objects (See below).\n\n**Option**\n\n- `ignoreCase`: `true` to ignore casing difference. Defaults to `false`.\n\n**Examples**\n\n- usage \n\n\u003e set `method=\"diffChars\"` to call `Diff.diffChars(oldStr, newStr[, options])` method\n\n````markdown\n{% diff method=\"diffChars\" %}\n```js\ncat\n```\n```js\ncap\n```\n{% enddiff %}\n````\n\n- preview \n\n```diff\n  ca\n- t\n+ p\n```\n\n#### `Diff.diffWords(oldStr, newStr[, options])`\n\n\u003e diffs two blocks of text, comparing word by word, ignoring whitespace.\n\n**Return**\n\nReturns a list of change objects (See below).\n\n**Option**\n\n- `ignoreCase`: Same as in `diffChars`.\n\n**Examples**\n\n- usage \n\n\u003e set `method=\"diffWords\"` to call `Diff.diffWords(oldStr, newStr[, options])` method\n\n````markdown\n{% diff method=\"diffWords\" %}\n```bash\nbeep boop  \n```\n```bash\nbeep boob blah\n```\n{% enddiff %}\n````\n\n- preview \n\n```diff\n  beep \n- boop\n+ boob\n\n+ blah\n```\n\n#### `Diff.diffWordsWithSpace(oldStr, newStr[, options])`\n\n\u003e diffs two blocks of text, comparing word by word, treating whitespace as significant.\n\n**Return**\n\nReturns a list of change objects (See below).\n\n**Option**\n\n- `ignoreCase`: Same as in `diffWords`.\n\n**Examples**\n\n- usage \n\n\u003e set `method=\"diffWordsWithSpace\"` to call `Diff.diffWordsWithSpace(oldStr, newStr[, options])` method\n\n````markdown\n{% diff method=\"diffWordsWithSpace\" %}\n```bash\nbeep boop  \n```\n```bash\nbeep boob blah\n```\n{% enddiff %}\n````\n\n- preview \n\n```diff\n  beep \n- boop\n+ boob blah\n```\n\n#### `Diff.diffLines(oldStr, newStr[, options])`\n\n\u003e diffs two blocks of text, comparing line by line.\n\n**Return**\n\nReturns a list of change objects (See below).\n\n**Option**\n\n- `ignoreWhitespace`: `true` to ignore leading and trailing whitespace. This is the same as `diffTrimmedLines`\n- `newlineIsToken`: `true` to treat newline characters as separate tokens.  This allows for changes to the newline structure to occur independently of the line content and to be treated as such. In general this is the more human friendly form of `diffLines` and `diffLines` is better suited for patches and other computer friendly output.\n\n**Examples**\n\n- usage \n\n\u003e set `method=\"diffLines\"` to call `Diff.diffLines(oldStr, newStr[, options])` method\n\n````markdown\n{% diff method=\"diffLines\",options={\"newlineIsToken\":true} %}\n```bash\nbeep boop\nthe cat is palying with cap\nwhat\n```\n```bash\nbeep boob blah\nthe cat is palying with cap\nwho\n```\n{% enddiff %}\n````\n\n- preview \n\n```diff\n- beep boop\n\n+ beep boob blah\n\n  the cat is palying with cap\n\n- what\n\n+ who\n```\n\n#### `Diff.diffTrimmedLines(oldStr, newStr[, options])`\n\n\u003e diffs two blocks of text, comparing line by line, ignoring leading and trailing whitespace.\n\n**Return**\n\nReturns a list of change objects (See below).\n\n**Option**\n\n- `ignoreWhitespace`: Same as in `diffLines`.\n- `newlineIsToken`: Same as in `diffLines`.\n\n**Examples**\n\n- usage \n\n\u003e set `method=\"diffTrimmedLines\"` to call `Diff.diffTrimmedLines(oldStr, newStr[, options])` method\n\n````markdown\n{% diff method=\"diffTrimmedLines\",options={\"newlineIsToken\":true} %}\n```bash\nbeep boop\nthe cat is palying with cap\nwhat\n```\n```bash\nbeep boob blah\nthe cat is palying with cat\nwho\n```\n{% enddiff %}\n````\n\n- preview \n\n```diff\n- beep boop\n  the cat is palying with cap\n  what\n\n+ beep boob blah\n  the cat is palying with cat\n  who\n```\n\n#### `Diff.diffSentences(oldStr, newStr[, options])`\n\n\u003e diffs two blocks of text, comparing sentence by sentence.\n\n**Return**\n\nReturns a list of change objects (See below).\n\n**Examples**\n\n- usage \n\n\u003e set `method=\"diffSentences\"` to call `Diff.diffSentences(oldStr, newStr[, options])` method\n\n````markdown\n{% diff method=\"diffSentences\" %}\n```bash\nbeep boop\nthe cat is palying with cap\nwhat\n```\n```bash\nbeep boob blah\nthe cat is palying with cat\nwho\n```\n{% enddiff %}\n````\n\n- preview \n\n```diff\n- beep boop\n  the cat is palying with cap\n  what\n\n+ beep boob blah\n  the cat is palying with cat\n  who\n```\n\n#### `Diff.diffJson(oldObj, newObj[, options])`\n\n\u003e diffs two JSON objects, comparing the fields defined on each. The order of fields, etc does not matter in this comparison.\n\n**Return**\n\nReturns a list of change objects (See below).\n\n**Examples**\n\n- usage \n\n\u003e set `method=\"diffJson\"` to call `Diff.diffJson(oldObj, newObj[, options])` method\n\n````markdown\n{% diff method=\"diffJson\" %}\n```json\n{\n  \"name\": \"gitbook-plugin-simple-mind-map\",\n  \"version\": \"0.2.1\",\n  \"description\": \"A gitBook plugin for generating and exporting mind map within markdown\"\n}\n```\n```json\n{\n  \"name\": \"gitbook-plugin-diff\",\n  \"version\": \"0.2.1\",\n  \"description\": \"A gitbook plugin for showing the differences between the codes within markdown\"\n}\n```\n{% enddiff %}\n````\n\n- preview \n\n```diff\n{\n-   \"description\": \"A gitBook plugin for generating and exporting mind map within markdown\",\n-   \"name\": \"gitbook-plugin-simple-mind-map\",\n+   \"description\": \"A gitbook plugin for showing the differences between the codes within markdown\",\n+   \"name\": \"gitbook-plugin-diff\",\n    \"version\": \"0.2.1\"\n}\n```\n\n#### `Diff.diffArrays(oldArr, newArr[, options])`\n\n\u003e diffs two arrays, comparing each item for strict equality (===).\n\n**Return**\n\nReturns a list of change objects (See below).\n\n**Options**\n\n- `comparator`: `function(left, right)` for custom equality checks\n\n**Examples**\n\n- usage \n\n\u003e set `method=\"diffArrays\"` to call `Diff.diffArrays(oldArr, newArr[, options])` method\n\n````markdown\n{% diff method=\"diffArrays\" %}\n```json\n[\n    \"Vue\",\n    \"Python\",\n    \"Java\",\n    \"flutter\",\n    \"springboot\",\n    \"docker\",\n    \"React\",\n    \"小程序\"\n]\n```\n```json\n[\n    \"Vuejs\",\n    \"Nodejs\",\n    \"Java\",\n    \"flutter\",\n    \"springboot\",\n    \"docker\",\n    \"React\"\n]\n```\n{% enddiff %}\n````\n\n- preview \n\n```diff\n[\n-   Vue\n-   Python\n+   Vuejs\n+   Nodejs\n    Java\n    flutter\n    springboot\n    docker\n    React\n-   小程序\n]\n```\n\n### Step #3 - Run gitbook commands\n\n1. Run `gitbook install`. It will automatically install `diff` gitbook plugin for your book. This is needed only once.\n\n```bash\ngitbook install\n```\n\nor you can run `npm install gitbook-plugin-diff` to install locally.\n\n```bash\nnpm install gitbook-plugin-diff\n```\n\n2. Build your book (`gitbook build`) or serve (`gitbook serve`) as usual.\n\n```bash\ngitbook serve\n```\n\n## Examples\n\n- Sample `book.json` file \n\n```json\n{\n    \"plugins\": [\"diff\"]\n}\n```\n\nor you can set `method` as your default method to compare between codes:\n\n```json\n{\n    \"plugins\": [\"diff\"],\n    \"pluginsConfig\": {\n        \"diff\": {\n            \"method\": \"diffChars\"\n        }\n    }\n}\n```\n\nor you can set `options` as your default settings according to method:\n\n```json\n{\n    \"plugins\": [\"diff\"],\n    \"pluginsConfig\": {\n        \"diff\": {\n            \"method\": \"diffChars\",\n            \"options\": {\n              \"ignoreCase\": true\n            }\n        }\n    }\n}\n```\n\n**Note**: Above snippet can be used as complete `book.json` file, if your book doesn't have one yet.\n\n## Thanks\n\n- A javascript text differencing implementation. : [https://github.com/kpdecker/jsdiff](https://github.com/kpdecker/jsdiff)\n- get colors in your node.js console : [https://github.com/Marak/colors.js](https://github.com/Marak/colors.js)\n- GitBook CodeGroup Plugin : [https://github.com/lwhiteley/gitbook-plugin-codegroup](https://github.com/lwhiteley/gitbook-plugin-codegroup)\n\n## Author\n\n👤 **snowdreams1006**\n\n- Website: [snowdreams1006.tech](https://snowdreams1006.tech/)\n- Github: [@snowdreams1006](https://github.com/snowdreams1006)\n- Email: [snowdreams1006@163.com](mailto:snowdreams1006@163.com)\n\n## Contributing\n\nContributions, issues and feature requests are welcome! Feel free to check [issues page](https://github.com/snowdreams1006/gitbook-plugin-diff/issues).\n\n## Show your support\n\nGive a [Star](https://github.com/snowdreams1006/gitbook-plugin-diff) if this project helped you!\n\n![snowdreams1006-wechat-donate.jpg](https://snowdreams1006.github.io/snowdreams1006-wechat-donate.jpg)\n\n## Copyright\n\nCopyright © 2019 [snowdreams1006](https://github.com/snowdreams1006).\n\nThis project is [MIT](https://github.com/snowdreams1006/gitbook-plugin-diff/blob/master/LICENSE) licensed.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnowdreams1006%2Fgitbook-plugin-diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnowdreams1006%2Fgitbook-plugin-diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnowdreams1006%2Fgitbook-plugin-diff/lists"}