Files
sgauthier 6e64e138e2
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
planning
2024-10-14 09:15:30 +02:00

47 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
module.exports = definition
var association = require('../util/association')
var checkQuote = require('../util/check-quote')
var safe = require('../util/safe')
function definition(node, _, context) {
var marker = checkQuote(context)
var suffix = marker === '"' ? 'Quote' : 'Apostrophe'
var exit = context.enter('definition')
var subexit = context.enter('label')
var value =
'[' + safe(context, association(node), {before: '[', after: ']'}) + ']: '
subexit()
if (
// If theres no url, or…
!node.url ||
// If theres whitespace, enclosed is prettier.
/[ \t\r\n]/.test(node.url)
) {
subexit = context.enter('destinationLiteral')
value += '<' + safe(context, node.url, {before: '<', after: '>'}) + '>'
} else {
// No whitespace, raw is prettier.
subexit = context.enter('destinationRaw')
value += safe(context, node.url, {before: ' ', after: ' '})
}
subexit()
if (node.title) {
subexit = context.enter('title' + suffix)
value +=
' ' +
marker +
safe(context, node.title, {before: marker, after: marker}) +
marker
subexit()
}
exit()
return value
}