-
Notifications
You must be signed in to change notification settings - Fork 1
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
Saektide
committed
Nov 16, 2020
1 parent
3f6e599
commit eedd7ab
Showing
12 changed files
with
5,349 additions
and
379 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 |
---|---|---|
|
@@ -60,5 +60,5 @@ typings/ | |
# next.js build output | ||
.next | ||
|
||
# Test folder | ||
tests/ | ||
# Internal dir | ||
internal/ |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Test dir | ||
tests/ | ||
# Internal dir | ||
internal/ |
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 |
---|---|---|
@@ -1,38 +1,45 @@ | ||
> :warning: WIP | ||
# DText parser | ||
DText is the e621's markdown system, it's based on many languages like BBCode, MediaWiki, Textile, etc. This module parses DText to HTML. | ||
|
||
# :u6e80: DText parser | ||
DText is the e621's markdown system, it's based on many languages like BBCode, MediaWiki, Textile, etc. | ||
|
||
## :package: Install | ||
## 📦 Install | ||
``` | ||
yarn add dtext-parser | ||
npm i -S dtext-parser | ||
``` | ||
or | ||
``` | ||
npm install dtext-parser -s | ||
yarn add dtext-parser | ||
``` | ||
|
||
## :wrench: Usage | ||
### Quick start | ||
## 🧪 Usage | ||
### ⚡ Quick start | ||
```js | ||
import DText from 'dtext-parser' | ||
const DText = require('dtext-parser'); | ||
|
||
DText.parse('h1.DText header') | ||
.then(console.log); // <h1>DText header</h1> | ||
.then(console.log); // <h1>DText header</h1> | ||
``` | ||
|
||
### Config | ||
### ⚙ Config | ||
Follow the name of the modules (codes) e.g. Bold, Italics, Code, External link, etc. then set your own class or style. | ||
```js | ||
import DText from 'dtext-parser' | ||
const DText = require('dtext-parser'); | ||
|
||
DText.options({ | ||
"External link": { | ||
style: "color:red; font-size:14pt", | ||
class: "external-link" | ||
attrs: [ | ||
{ | ||
name: 'style', | ||
value: 'color: red;' | ||
}, | ||
{ | ||
name: 'class', | ||
value: 'extern' | ||
} | ||
] | ||
} | ||
}); | ||
}); | ||
|
||
DText.parse('https://github.com').then(console.log); | ||
// <a href="https://github.com" class="external-link" style="color:red; font-size:14pt">https://github.com</a> | ||
// <a href="https://github.com" class="extern" style="color: red;">https://github.com</a> | ||
``` |
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,161 @@ | ||
const dtext = require('../'); | ||
|
||
test('parse format Bold', () => { | ||
return dtext.parse('[b]Test[/b]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<b>Test</b>'); | ||
}); | ||
}); | ||
|
||
test('parse format Italics', () => { | ||
return dtext.parse('[i]Test[/i]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<i>Test</i>'); | ||
}); | ||
}); | ||
|
||
test('parse format Underline', () => { | ||
return dtext.parse('[u]Test[/u]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<u>Test</u>'); | ||
}); | ||
}); | ||
|
||
test('parse format Overline', () => { | ||
return dtext.parse('[o]Test[/o]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<o>Test</o>'); | ||
}); | ||
}); | ||
|
||
test('parse format Strikeout', () => { | ||
return dtext.parse('[s]Test[/s]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<s>Test</s>'); | ||
}); | ||
}); | ||
|
||
test('parse format Superscript', () => { | ||
return dtext.parse('[sup]Test[/sup]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<sup>Test</sup>'); | ||
}); | ||
}); | ||
|
||
test('parse format Subscript', () => { | ||
return dtext.parse('[sub]Test[/sub]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<sub>Test</sub>'); | ||
}); | ||
}); | ||
|
||
test('parse format Username', () => { | ||
return dtext.parse('@Test') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<b>@Test</b>'); | ||
}); | ||
}); | ||
|
||
test('parse format Spoiler', () => { | ||
return dtext.parse('[spoiler]Test[/spoiler]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<span class="spoiler">Test</span>'); | ||
}); | ||
}); | ||
|
||
test('parse format Code', () => { | ||
return dtext.parse('`Test`') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<code>Test</code>'); | ||
}); | ||
}); | ||
|
||
test('parse format Inline code', () => { | ||
return dtext.parse('`Test`') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<code>Test</code>'); | ||
}); | ||
}); | ||
|
||
test('parse format Color', () => { | ||
return dtext.parse('[color=#f00]Test[/color]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<span style="color:#f00">Test</span>'); | ||
}); | ||
}); | ||
|
||
test('parse format External link', () => { | ||
return dtext.parse('https://google.com') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<a href="https://google.com">https://google.com</a>'); | ||
}); | ||
}); | ||
|
||
test('parse format Wiki link', () => { | ||
return dtext.parse('[[test]]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<a href="https://e621.net/wiki_pages/test">test</a>'); | ||
}); | ||
}); | ||
|
||
test('parse format Tag link', () => { | ||
return dtext.parse('{{test}}') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<a href="https://e621.net/posts?tags=test">test</a>'); | ||
}); | ||
}); | ||
|
||
test('parse format Intern link', () => { | ||
return dtext.parse('post #1234') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<a href="https://e621.net/posts/1234">post #1234</a>'); | ||
}); | ||
}); | ||
|
||
test('parse format Quote', () => { | ||
return dtext.parse('[quote]Test[/quote]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<blockquote>Test</blockquote>'); | ||
}); | ||
}); | ||
|
||
test('parse format Code', () => { | ||
return dtext.parse('[code]Test[/code]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<pre>Test</pre>'); | ||
}); | ||
}); | ||
|
||
test('parse format Header', () => { | ||
return dtext.parse('h1.Test') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<h1>Test</h1>'); | ||
}); | ||
}); | ||
|
||
test('parse format Section', () => { | ||
return dtext.parse('[section,expanded="Test"]Test[/section]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<section class="section collapsed"><div class="section-collapse-title">"Test"]Test[/section</div><div class="section-collapsed-title">"Test"]Test[/section</div><div class="section-content">'); | ||
}); | ||
}); |
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,23 @@ | ||
const dtext = require('../'); | ||
|
||
test('parse html attributes', () => { | ||
dtext.options({ | ||
"External link": { | ||
attrs: [ | ||
{ | ||
name: 'style', | ||
value: 'color: red;' | ||
}, | ||
{ | ||
name: 'class', | ||
value: 'extern' | ||
} | ||
] | ||
} | ||
}); | ||
|
||
return dtext.parse('https://google.com').then((result) => { | ||
expect(result).toBe | ||
('<a href="https://google.com" style="color: red;" class="extern">https://google.com</a>'); | ||
}); | ||
}); |
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,25 @@ | ||
const dtext = require('../'); | ||
|
||
test('parse scenario Simple article', () => { | ||
return dtext.parse('h1.Hello\nHello world!') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<h1>Hello</h1><p>Hello world!</p>'); | ||
}); | ||
}); | ||
|
||
test('parse scenario Paragraphs', () => { | ||
return dtext.parse('Hello foo!\nHello bar!') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<p>Hello foo!</p><p>Hello bar!</p>'); | ||
}); | ||
}); | ||
|
||
test('parse scenario Section', () => { | ||
return dtext.parse('[section=Section title]\nh1.Some cool title\nRemake of post #1234[/section]') | ||
.then((result) => { | ||
expect(result).toBe | ||
('<section class="section expanded"><div class="section-collapse-title">Section title</div><div class="section-collapsed-title">Section title</div><div class="section-content"><h1>Some cool title</h1><p>Remake of <a href="https://e621.net/posts/1234">post #1234</a></p>\n</div></section>'); | ||
}); | ||
}); |
Oops, something went wrong.