-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Introduce markdown renderer #480
Open
miguelcrespo
wants to merge
9
commits into
contentful:master
Choose a base branch
from
miguelcrespo:feat/markdown-renderer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
37c6c2e
feat: first commit markdown-renderer
miguelcrespo 02ea390
doc: update docs
miguelcrespo 1597990
test: add support for custom renderers
miguelcrespo 32f01ce
feat: update readme
miguelcrespo 6865d7f
fix: remove unnecesary file
miguelcrespo a276d4a
fix: remove commented code
miguelcrespo e601c80
fix: remove package-lock
miguelcrespo dffe225
feat: add support for nested lists
miguelcrespo e0f3204
Merge branch 'master' into feat/markdown-renderer
miguelcrespo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# rich-text-markdown-renderer | ||
|
||
A library to convert Contentful Rich Text Document to Markdown in [Github Markdown Format (gmf)](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax). | ||
|
||
## Installation | ||
|
||
Using [npm](http://npmjs.org/): | ||
|
||
```sh | ||
npm install @contentful/rich-text-markdown-renderer | ||
``` | ||
|
||
Using [yarn](https://yarnpkg.com/): | ||
|
||
```sh | ||
yarn add @contentful/rich-text-markdown-renderer | ||
``` | ||
|
||
## Features | ||
|
||
- Support for ordered lists 🔢 | ||
- Extend default behavior with custom renderers 🔧 | ||
|
||
## Usage | ||
|
||
### Basic | ||
|
||
```javascript | ||
import { documentToMarkdown } from '@contentful/rich-text-markdown-renderer'; | ||
|
||
const document = { | ||
nodeType: 'document', | ||
data: {}, | ||
content: [ | ||
{ | ||
nodeType: 'paragraph', | ||
data: {}, | ||
content: [ | ||
{ | ||
nodeType: 'text', | ||
value: 'Hello', | ||
marks: [{ type: 'bold' }], | ||
data: {}, | ||
}, | ||
{ | ||
nodeType: 'text', | ||
value: ' world!', | ||
marks: [{ type: 'italic' }], | ||
data: {}, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
documentToMarkdown(document)); // -> Hello world! | ||
``` | ||
|
||
### Advanced | ||
|
||
```javascript | ||
documentToMarkdown(document, { | ||
renderNode: { | ||
[BLOCKS.EMBEDDED_ASSET]: (node) => { | ||
return `![${node.data.target.fields.title}](${node.data.target.fields.file.url})\n`; | ||
}, | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../../bin/tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../../bin/tslint.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const getBaseConfig = require('../../baseJestConfig'); | ||
const package = require('./package.json'); | ||
const packageName = package.name.split('@contentful/')[1]; | ||
|
||
module.exports = { | ||
...getBaseConfig(packageName), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@contentful/rich-text-markdown-renderer", | ||
"version": "16.0.5", | ||
"main": "dist/rich-text-markdown-renderer.es5.js", | ||
"typings": "dist/types/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/contentful/rich-text.git" | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=6.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build": "tsc --module commonjs && rollup -c rollup.config.js", | ||
"prebuild": "rimraf dist", | ||
"start": "tsc && rollup -c rollup.config.js -w", | ||
"lint": "tslint -t codeFrame '@(src|bin)/*.ts'", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"@contentful/rich-text-html-renderer": "^16.1.0", | ||
"@contentful/rich-text-types": "^16.2.0", | ||
"he": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/he": "^1.2.0", | ||
"jest": "^27.1.0", | ||
"rimraf": "^2.6.3", | ||
"rollup": "^1.32.1", | ||
"rollup-plugin-commonjs": "^9.3.4", | ||
"rollup-plugin-json": "^4.0.0", | ||
"rollup-plugin-node-resolve": "^4.2.4", | ||
"rollup-plugin-sourcemaps": "^0.6.3", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"ts-jest": "^27.0.5", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.4.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import config from '../../rollup.config'; | ||
import { main as outputFile } from './package.json'; | ||
|
||
export default config(outputFile); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for now but we should really migrate all the builds in this repo to SWC