MCPcopy Index your code
hub / github.com/marijnh/Eloquent-JavaScript / smartQuotes

Function smartQuotes

src/transform.mjs:32–53  ·  view source on GitHub ↗
(tokens, i, tex, moveQuotes)

Source from the content-addressed store, hash-verified

30}
31
32function smartQuotes(tokens, i, tex, moveQuotes) {
33 let text = tokens[i].content, from = 0
34 for (let j = i - 1, tt; j >= 0; j--) if (tt = tokenText(tokens[j])) {
35 text = tt + text
36 from = tt.length
37 break
38 }
39 let to = text.length
40 for (let j = i + 1, tt; j < tokens.length; j++) if (tt = tokenText(tokens[j])) {
41 text += tt
42 break
43 }
44
45 let quoted = text
46 .replace(/([\w\.,!?\)])'/g, "$1’")
47 .replace(/'(\w|\(\()/g, "‘$1")
48 .replace(/([\w\.,!?\)])"/g, "$1”")
49 .replace(/"(\w|\(\()/g, "“$1")
50 .slice(from, to)
51 if (moveQuotes) quoted = quoted.replace(/”([.!?:;,]+)/g, "$1”")
52 return tex ? quoted.replace(/‘/g, "`").replace(/’/g, "'").replace(/“/g, "``").replace(/”/g, "''") : quoted
53}
54
55function handleIf(tokens, i, options) {
56 let tag = tokens[i].args[0]

Callers 1

transformInlineFunction · 0.85

Calls 1

tokenTextFunction · 0.85

Tested by

no test coverage detected