forked from holamgadol/markdownlint-foliant-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypograph.js
51 lines (50 loc) · 1.32 KB
/
typograph.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
const hyphenBetweenWords = /[^\s\\>] - [^\s\\]/
const dashBetweenWords = /[^\s\\>]–[^\s\\]/
const {
addError,
forEachInlineChild,
rangeFromRegExp
} = require('markdownlint-rule-helpers')
module.exports = {
names: ['typograph'],
description: 'typograph error',
information: new URL('https://github.com/holamgadol/markdownlint-foliant-rules#typograph'),
tags: ['text'],
function: function typograph (params, onError) {
forEachInlineChild(params, 'text', function forToken (token) {
if (hyphenBetweenWords.test(token.line)) {
const range = rangeFromRegExp(token.line, hyphenBetweenWords)
const fixInfo = {
editColumn: range[0] + 2,
deleteCount: 1,
insertText: '–'
}
addError(
onError,
token.lineNumber,
'hyphen instead of dash',
null,
range,
fixInfo
)
}
if (dashBetweenWords.test(token.line)) {
const range = rangeFromRegExp(token.line, dashBetweenWords)
const fixInfo = {
editColumn: range[0] + 1,
deleteCount: 1,
insertText: '-'
}
addError(
onError,
token.lineNumber,
'dash instead of hyphen',
null,
range,
fixInfo
)
}
})
}
}