Skip to content

Commit

Permalink
Change fences default to true
Browse files Browse the repository at this point in the history
Closes GH-49.
  • Loading branch information
wooorm committed Jul 9, 2023
1 parent 019f25f commit 7f91d06
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
4 changes: 2 additions & 2 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@
* Marker to use for emphasis (default: `'*'`).
* @property {'`' | '~' | null | undefined} [fence='`']
* Marker to use for fenced code (default: ``'`'``).
* @property {boolean | null | undefined} [fences=false]
* Whether to use fenced code always (default: `false`).
* @property {boolean | null | undefined} [fences=true]
* Whether to use fenced code always (default: `true`).
*
* The default is to use fenced code if there is a language defined, if the
* code is empty, or if it starts or ends in blank lines.
Expand Down
2 changes: 1 addition & 1 deletion lib/util/format-code-as-indented.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
export function formatCodeAsIndented(node, state) {
return Boolean(
!state.options.fences &&
state.options.fences === false &&
node.value &&
// If there’s no info…
!node.lang &&
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ Marker to use for fenced code (``'`'`` or `'~'`, default: ``'`'``).

###### `options.fences`

Whether to use fenced code always (`boolean`, default: `false`).
Whether to use fenced code always (`boolean`, default: `true`).
The default is to use fenced code if there is a language defined, if the code is
empty, or if it starts or ends in blank lines.

Expand Down
62 changes: 34 additions & 28 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,17 @@ test('core', async function (t) {
'should inject HTML comments between lists and an indented code',
async function () {
assert.equal(
to({
type: 'root',
children: [
{type: 'code', value: 'a'},
{type: 'list', children: [{type: 'listItem', children: []}]},
{type: 'code', value: 'b'}
]
}),
to(
{
type: 'root',
children: [
{type: 'code', value: 'a'},
{type: 'list', children: [{type: 'listItem', children: []}]},
{type: 'code', value: 'b'}
]
},
{fences: false}
),
' a\n\n*\n\n<!---->\n\n b\n'
)
}
Expand All @@ -134,13 +137,16 @@ test('core', async function (t) {
'should inject HTML comments between adjacent indented code',
async function () {
assert.equal(
to({
type: 'root',
children: [
{type: 'code', value: 'a'},
{type: 'code', value: 'b'}
]
}),
to(
{
type: 'root',
children: [
{type: 'code', value: 'a'},
{type: 'code', value: 'b'}
]
},
{fences: false}
),
' a\n\n<!---->\n\n b\n'
)
}
Expand Down Expand Up @@ -371,10 +377,13 @@ test('blockquote', async function (t) {
'should support code (flow, indented) in a block quote',
async function () {
assert.equal(
to({
type: 'blockquote',
children: [{type: 'code', value: 'a\nb\n\nc'}]
}),
to(
{
type: 'blockquote',
children: [{type: 'code', value: 'a\nb\n\nc'}]
},
{fences: false}
),
'> a\n> b\n>\n> c\n'
)
}
Expand Down Expand Up @@ -799,14 +808,11 @@ test('code (flow)', async function (t) {
)

await t.test('should support code w/ a value (indent)', async function () {
assert.equal(to({type: 'code', value: 'a'}), ' a\n')
assert.equal(to({type: 'code', value: 'a'}, {fences: false}), ' a\n')
})

await t.test('should support code w/ a value (fences)', async function () {
assert.equal(
to({type: 'code', value: 'a'}, {fences: true}),
'```\na\n```\n'
)
assert.equal(to({type: 'code', value: 'a'}), '```\na\n```\n')
})

await t.test('should support code w/ a lang', async function () {
Expand Down Expand Up @@ -904,7 +910,7 @@ test('code (flow)', async function (t) {
'should use more grave accents for fences if there are streaks of grave accents in the value (fences)',
async function () {
assert.equal(
to({type: 'code', value: '```\nasd\n```'}, {fences: true}),
to({type: 'code', value: '```\nasd\n```'}),
'````\n```\nasd\n```\n````\n'
)
}
Expand All @@ -914,7 +920,7 @@ test('code (flow)', async function (t) {
'should use more tildes for fences if there are streaks of tildes in the value (fences)',
async function () {
assert.equal(
to({type: 'code', value: '~~~\nasd\n~~~'}, {fence: '~', fences: true}),
to({type: 'code', value: '~~~\nasd\n~~~'}, {fence: '~'}),
'~~~~\n~~~\nasd\n~~~\n~~~~\n'
)
}
Expand Down Expand Up @@ -963,7 +969,7 @@ test('code (flow)', async function (t) {
'should use an indent if the value is indented',
async function () {
assert.equal(
to({type: 'code', value: ' a\n\n b'}),
to({type: 'code', value: ' a\n\n b'}, {fences: false}),
' a\n\n b\n'
)
}
Expand Down Expand Up @@ -4501,7 +4507,7 @@ test('roundtrip', async function (t) {
''
].join('\n')

assert.equal(to(from(doc)), doc)
assert.equal(to(from(doc), {fences: false}), doc)
}
)

Expand Down

0 comments on commit 7f91d06

Please sign in to comment.