-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 43afab2
Showing
16 changed files
with
479 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: publish package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
publish-npm: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
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,19 @@ | ||
name: Node.js CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Test with Node.js 12 | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
- run: npm install | ||
- run: npm test | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
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 @@ | ||
node_modules/ | ||
coverage/ | ||
.DS_Store |
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,5 @@ | ||
dist/ | ||
test/ | ||
.github | ||
coverage/ | ||
*.config.js |
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 @@ | ||
0.1.1 | ||
------------------ | ||
|
||
- First release. |
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,22 @@ | ||
Copyright (c) 2020 wavesheep. | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
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,59 @@ | ||
# markdown-it-plain-text | ||
|
||
 | ||
 | ||
[](https://codecov.io/gh/wavesheep/markdown-it-plain-text) | ||
 | ||
[](https://www.npmjs.com/package/markdown-it-plain-text) | ||
|
||
> plain text extractor for markdown-it | ||
## Install | ||
|
||
### nodejs | ||
|
||
```shell | ||
npm install markdown-it-plain-text | ||
``` | ||
|
||
### browser (CDN) | ||
|
||
### uncompressed | ||
[https://cdn.jsdelivr.net/gh/wavesheep/[email protected]/dist/markdown-it-plain-text.js](https://cdn.jsdelivr.net/gh/wavesheep/[email protected]/dist/markdown-it-plain-text.js) | ||
### compressed | ||
[https://cdn.jsdelivr.net/gh/wavesheep/[email protected]/dist/markdown-it-plain-text.min.js](https://cdn.jsdelivr.net/gh/wavesheep/[email protected]/dist/markdown-it-plain-text.js) | ||
|
||
## Usage examples | ||
|
||
### Node.js | ||
|
||
```js | ||
const MarkdownIt = require('markdown-it'); | ||
const plainText = require('markdown-it-plain-text'); | ||
|
||
const md = new MarkdownIt(); | ||
md.use(plainText); | ||
|
||
md.render('your markdown content') | ||
|
||
// Here are plain text result | ||
md.plainText | ||
``` | ||
|
||
### Browser | ||
|
||
If you load the script directly into the page without using a package system, the module will add itself globally with the name `markdownItPlainTextPlugin`. Init code will look a bit different in this case: | ||
|
||
```js | ||
const md = window.markdownit().use(window.markdownItPlainTextPlugin); | ||
``` | ||
|
||
## Generation rule | ||
|
||
1. extract `text`, `fence`, `html_block`, `code_block`, `html_inline`, `emoji` content directly | ||
2. add `space` at closing tag to *prevent words from sticking together* | ||
3. *remove redundant white spaces* from result | ||
|
||
## LICENSE | ||
|
||
[MIT](LICENSE) |
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,41 @@ | ||
var markdownItPlainTextPlugin = (function () { | ||
'use strict'; | ||
|
||
var markdownItPlainText = function plainTextPlugin(md) { | ||
function plainTextRule(state) { | ||
var text = scan(state.tokens); | ||
// remove redundant white spaces | ||
md.plainText = text.replace(/\s+/g, " "); | ||
} | ||
|
||
function scan(tokens) { | ||
var text = ''; | ||
for (var i = 0; i < tokens.length; i++) { | ||
var token = tokens[i]; | ||
if (token.children !== null) { | ||
text += scan(token.children); | ||
} else { | ||
if ( | ||
token.type === 'text' || | ||
token.type === 'fence' || | ||
token.type === 'html_block' || | ||
token.type === 'code_block' || | ||
token.type === 'html_inline' || | ||
token.type === 'emoji' | ||
) { | ||
text += token.content; | ||
} else if (/[a-zA-Z]+_close/.test(token.type)) { // prevent words from sticking together | ||
text += " "; | ||
} | ||
} | ||
} | ||
|
||
return text; | ||
} | ||
|
||
md.core.ruler.push('plainText', plainTextRule); | ||
}; | ||
|
||
return markdownItPlainText; | ||
|
||
}()); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,36 @@ | ||
'use strict'; | ||
|
||
module.exports = function plainTextPlugin(md) { | ||
function plainTextRule(state) { | ||
var text = scan(state.tokens); | ||
// remove redundant white spaces | ||
md.plainText = text.replace(/\s+/g, " "); | ||
} | ||
|
||
function scan(tokens) { | ||
var text = ''; | ||
for (var i = 0; i < tokens.length; i++) { | ||
var token = tokens[i]; | ||
if (token.children !== null) { | ||
text += scan(token.children); | ||
} else { | ||
if ( | ||
token.type === 'text' || | ||
token.type === 'fence' || | ||
token.type === 'html_block' || | ||
token.type === 'code_block' || | ||
token.type === 'html_inline' || | ||
token.type === 'emoji' | ||
) { | ||
text += token.content; | ||
} else if (/[a-zA-Z]+_close/.test(token.type)) { // prevent words from sticking together | ||
text += " " | ||
} | ||
} | ||
} | ||
|
||
return text; | ||
} | ||
|
||
md.core.ruler.push('plainText', plainTextRule); | ||
} |
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,6 @@ | ||
module.exports = { | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'index.js' | ||
], | ||
} |
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,34 @@ | ||
{ | ||
"name": "markdown-it-plain-text", | ||
"version": "0.1.1", | ||
"description": "plain text extractor plugin for markdown-it markdown parser", | ||
"keywords": [ | ||
"markdown-it-plugin", | ||
"markdown-it", | ||
"markdown", | ||
"plain text", | ||
"plain-text" | ||
], | ||
"repository": "wavesheep/markdown-it-plain-text.git", | ||
"homepage": "https://github.com/wavesheep/markdown-it-plain-text#readme", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jest", | ||
"build:prod": "cross-env NODE_ENV=production rollup -c", | ||
"build:dev": "cross-env NODE_ENV=dev rollup -c", | ||
"build": "npm run build:prod && npm run build:dev", | ||
"dev": "rollup -c -w" | ||
}, | ||
"author": "wavesheep <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^13.0.0", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"cross-env": "^7.0.2", | ||
"jest": "^26.1.0", | ||
"markdown-it": "^11.0.0", | ||
"markdown-it-emoji": "^1.4.0", | ||
"rollup": "^2.18.1", | ||
"rollup-plugin-terser": "^6.1.0" | ||
} | ||
} |
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,24 @@ | ||
import path from 'path' | ||
import { name } from './package.json'; | ||
import json from '@rollup/plugin-json'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
|
||
const isDev = process.env.NODE_ENV !== 'production'; | ||
|
||
export default { | ||
input: 'index.js', | ||
output: { | ||
file: !isDev ? path.resolve(`dist/${name}.min.js`) : path.resolve(`dist/${name}.js`), | ||
format: 'iife', | ||
name: 'markdownItPlainTextPlugin' | ||
}, | ||
plugins: [ | ||
json(), | ||
commonjs(), | ||
!isDev && terser() | ||
] | ||
} | ||
|
||
|
||
|
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 @@ | ||
Advertisement :) pica - high quality and fast imageresize in browser. babelfish - developer friendlyi18n with plurals support and easy syntax. You will like those projects! h1 Heading 8-) h2 Heading h3 Heading h4 Heading h5 Heading h6 Heading Horizontal Rules Typographic replacements Enable typographer option to see result. (c) (C) (r) (R) (tm) (TM) (p) (P) +- test.. test... test..... test?..... test!.... !!!!!! ???? ,, -- --- "Smartypants, double quotes" and 'single quotes' Emphasis This is bold text This is bold text This is italic text This is italic text Strikethrough Blockquotes Blockquotes can also be nested... ...by using additional greater-than signs right next to each other... ...or with spaces between arrows. Lists Unordered Create a list by starting a line with , , or Sub-lists are made by indenting 2 spaces: Marker character change forces new list start: Ac tristique libero volutpat at Facilisis in pretium nisl aliquet Nulla volutpat aliquam velit Very easy! Ordered Lorem ipsum dolor sit amet Consectetur adipiscing elit Integer molestie lorem at massa You can use sequential numbers... ...or keep all the numbers as Start numbering with offset: foo bar Code Inline Indented code // Some comments line 1 of code line 2 of code line 3 of code Block code "fences" Sample text here... Syntax highlighting var foo = function (bar) { return bar++; }; console.log(foo(5)); Tables Option Description data path to data files to supply the data that will be passed into templates. engine engine to be used for processing templates. Handlebars is the default. ext extension to be used for dest files. Right aligned columns Option Description data path to data files to supply the data that will be passed into templates. engine engine to be used for processing templates. Handlebars is the default. ext extension to be used for dest files. Links link text link with title Autoconverted link https://github.com/nodeca/pica (enable linkify to see) Images MinionStormtroopocat Like links, Images also have a footnote style syntax Alt text With a reference later in the document defining the URL location: |
Oops, something went wrong.