-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/cristianvasquez/obsidian-prettify/issues/85
- Loading branch information
1 parent
624ed0d
commit aa08ca6
Showing
9 changed files
with
157 additions
and
61 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
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
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,153 +1,174 @@ | ||
import prettifier from '../prettifier' | ||
|
||
test("Basic functionality: a formatted table", () => { | ||
const content = ` | ||
const content = ` | ||
**A**|**B**|**C** | ||
|---:|:---|---| | ||
|a |b |c| | ||
|x |y |z|`; | ||
return prettifier(content,{},{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Basic functionality: lists use * bullets", () => { | ||
const content = ` | ||
const content = ` | ||
- a | ||
- b | ||
- c | ||
- d | ||
- e | ||
- f | ||
`; | ||
return prettifier(content, { bullet: "*" },{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {bullet: "*"}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Basic functionality: lists use - bullets", () => { | ||
const content = ` | ||
const content = ` | ||
* a | ||
* b | ||
* c | ||
* d | ||
* e | ||
* f | ||
`; | ||
return prettifier(content,{},{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Basic functionality: alternating keeps information of different codification", () => { | ||
const content = ` | ||
const content = ` | ||
- a | ||
- b | ||
* c | ||
- d | ||
- e | ||
* f | ||
`; | ||
return prettifier(content, { bullet: "*" },{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {bullet: "*"}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Basic functionality: enumerate lists", () => { | ||
const content = ` | ||
const content = ` | ||
1. foo | ||
a. aaa | ||
b. bbb | ||
c. ccc | ||
1. bar | ||
1. baz | ||
`; | ||
return prettifier(content,{},{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Basic functionality: enumerate lists", () => { | ||
const content = ` | ||
const content = ` | ||
1. foo | ||
1. aaa | ||
1. bbb | ||
4. ccc | ||
1. bar | ||
1. baz | ||
`; | ||
return prettifier(content,{},{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Basic functionality: dont break obsidian links", () => { | ||
const content = `[[respect this]]`; | ||
return prettifier(content,{},{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
const content = `[[respect this]]`; | ||
return prettifier(content, {}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Embed youtube", () => { | ||
const content = ` | ||
const content = ` | ||
https://www.youtube.com/watch?v=B6rKUf9DWRI | ||
`; | ||
return prettifier(content,{},{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Embed image", () => { | ||
const content = ` | ||
const content = ` | ||
https://cyberculturesblog.files.wordpress.com/2019/01/Memex.jpg | ||
`; | ||
return prettifier(content,{},{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Indent size", () => { | ||
const content = ` | ||
const content = ` | ||
- foo | ||
- foo | ||
- foo | ||
- foo | ||
`; | ||
return prettifier(content, { listItemIndent: "one" },{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {listItemIndent: "one"}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Indent size", () => { | ||
const content = ` | ||
const content = ` | ||
- foo | ||
- foo | ||
- foo | ||
- foo | ||
`; | ||
return prettifier(content, { listItemIndent: "tab" },{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {listItemIndent: "tab"}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test('Newlines around headings: enabled', () => { | ||
const content = ` | ||
const content = ` | ||
# Heading | ||
Content | ||
## Subheading | ||
`; | ||
return prettifier(content, { newlinesAroundHeadings: true },{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {newlinesAroundHeadings: true}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Basic functionality: no spread", () => { | ||
const content = ` | ||
* one | ||
* two | ||
`; | ||
return prettifier(content, {}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test("Quoted test", () => { | ||
const content = ` | ||
> quoted test | ||
`; | ||
return prettifier(content, {}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test('Newlines around headings: disabled', () => { | ||
const content = ` | ||
const content = ` | ||
# Heading | ||
Content | ||
## Subheading | ||
`; | ||
return prettifier(content, { newlinesAroundHeadings: false },{}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
return prettifier(content, {newlinesAroundHeadings: false}, {}).then((data) => { | ||
expect(data.contents).toMatchSnapshot(); | ||
}); | ||
|
||
|
||
}); |
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,15 @@ | ||
module.exports = blockquote | ||
|
||
var flow = require('../util/container-flow') | ||
var indentLines = require('../util/indent-lines') | ||
|
||
function blockquote(node, _, context) { | ||
var exit = context.enter('blockquote') | ||
var value = indentLines(flow(node, context), map) | ||
exit() | ||
return value | ||
} | ||
|
||
function map(line, index, blank) { | ||
return '>' + (blank ? '' : ' ') + line | ||
} |
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,47 @@ | ||
module.exports = listItem | ||
|
||
var repeat = require('repeat-string') | ||
var checkBullet = require('../util/check-bullet') | ||
var checkListItemIndent = require('../util/check-list-item-indent') | ||
var flow = require('../util/container-flow') | ||
var indentLines = require('../util/indent-lines') | ||
|
||
function listItem(node, parent, context) { | ||
var bullet = checkBullet(context) | ||
var listItemIndent = checkListItemIndent(context) | ||
var size | ||
var value | ||
var exit | ||
|
||
if (parent && parent.ordered) { | ||
bullet = | ||
(parent.start > -1 ? parent.start : 1) + | ||
(context.options.incrementListMarker === false | ||
? 0 | ||
: parent.children.indexOf(node)) + | ||
'.' | ||
} | ||
|
||
size = bullet.length + 1 | ||
|
||
if ( | ||
listItemIndent === 'tab' || | ||
(listItemIndent === 'mixed' && ((parent && parent.spread) || node.spread)) | ||
) { | ||
size = Math.ceil(size / 4) * 4 | ||
} | ||
|
||
exit = context.enter('listItem') | ||
value = indentLines(flow(node, context), map) | ||
exit() | ||
|
||
return value | ||
|
||
function map(line, index, blank) { | ||
if (index) { | ||
return (blank ? '' : repeat(' ', size)) + line | ||
} | ||
|
||
return (blank ? bullet : bullet + repeat(' ', size - bullet.length)) + line | ||
} | ||
} |
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