Skip to content

Commit

Permalink
Removed unnecessary internal punctuation escaping ($&~) in citations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Witiko committed Apr 27, 2017
1 parent 8fffd05 commit f0cff9c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
27 changes: 20 additions & 7 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -2651,23 +2651,34 @@ function M.writer.new(options)
["^"] = "\\markdownRendererCircumflex{}",
["\\"] = "\\markdownRendererBackslash{}",
["~"] = "\\markdownRendererTilde{}",
["|"] = "\\markdownRendererPipe{}", }
local escaped_minimal_chars = {
["|"] = "\\markdownRendererPipe{}",
}
local escaped_uri_chars = {
["{"] = "\\markdownRendererLeftBrace{}",
["}"] = "\\markdownRendererRightBrace{}",
["%"] = "\\markdownRendererPercentSign{}",
["\\"] = "\\markdownRendererBackslash{}", }
["\\"] = "\\markdownRendererBackslash{}",
}
local escaped_citation_chars = {
["{"] = "\\markdownRendererLeftBrace{}",
["}"] = "\\markdownRendererRightBrace{}",
["%"] = "\\markdownRendererPercentSign{}",
["#"] = "\\markdownRendererHash{}",
["\\"] = "\\markdownRendererBackslash{}",
}
local escaped_minimal_strings = {
["^^"] = "\\markdownRendererCircumflex\\markdownRendererCircumflex ", }
["^^"] = "\\markdownRendererCircumflex\\markdownRendererCircumflex ",
}
% \end{macrocode}
% Use the \luam{escaped_chars} table to create an escaper function
% \luamdef{escape} and the \luam{escaped_minimal_chars} and
% \luam{escaped_minimal_strings} tables to create an escaper function
% \luamdef{escape_minimal}.
% \begin{macrocode}
local escape = util.escaper(escaped_chars)
local escape_minimal = util.escaper(escaped_minimal_chars,
local escape_citation = util.escaper(escaped_citation_chars,
escaped_minimal_strings)
local escape_uri = util.escaper(escaped_uri_chars, escaped_minimal_strings)
% \end{macrocode}
%
% Define \luamdef{writer->string} as a function that will transform an input
Expand All @@ -2678,10 +2689,12 @@ function M.writer.new(options)
% \begin{macrocode}
if options.hybrid then
self.string = function(s) return s end
self.citation = function(c) return c end
self.uri = function(u) return u end
else
self.string = escape
self.uri = escape_minimal
self.citation = escape_citation
self.uri = escape_uri
end
% \end{macrocode}
%
Expand Down Expand Up @@ -3720,7 +3733,7 @@ function M.reader.new(writer, options)
cites[#cites+1] = {
prenote = normalize(raw_cites[i]),
suppress_author = raw_cites[i+1] == "-",
name = writer.string(raw_cites[i+2]),
name = writer.citation(raw_cites[i+2]),
postnote = normalize(raw_cites[i+3]),
}
end
Expand Down
8 changes: 4 additions & 4 deletions tests/testfiles/lunamark-markdown/citations-escapes.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ default.

Here is a simple parenthetical citation \[\@doe99] and here
is a string of several [see @doe99, pp\; 33-35; also
@smit:.#$%&-+?<>~/h04, chap. 1].
@smit:.#$%&-+?<>_/h04, chap. 1].

A parenthetical citation can have a [prenote @doe99] and a
[@smith04 postnote]. The name of the author can be
suppressed by inserting a dash before the name of an author
as follows [\-@smith04].

Here is a simple text citation \@doe99 and here is a string
of several @doe99 [pp\; 33-35; also @smit:.#$%&-+?<>~/h04,
of several @doe99 [pp\; 33-35; also @smit:.#$%&-+?<>_/h04,
chap. 1]. Here is one with the name of the author
suppressed \-@doe99.
>>>
Expand All @@ -31,7 +31,7 @@ BEGIN cite
- suppressAuthor: false
- prenote: also
- postnote: chap.(nbsp)1
- name: smit:.(hash)(dollarSign)(percentSign)(ampersand)-+?<>(tilde)/h04
- name: smit:.(hash)$(percentSign)&-+?<>_/h04
END cite
interblockSeparator
BEGIN cite
Expand Down Expand Up @@ -63,7 +63,7 @@ BEGIN textCite
- suppressAuthor: false
- prenote: also
- postnote: chap.(nbsp)1
- name: smit:.(hash)(dollarSign)(percentSign)(ampersand)-+?<>(tilde)/h04
- name: smit:.(hash)$(percentSign)&-+?<>_/h04
END textCite
BEGIN textCite
- suppressAuthor: false
Expand Down
8 changes: 4 additions & 4 deletions tests/testfiles/lunamark-markdown/citations-nbsps.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default.

Here is a simple parenthetical citation [@doe99] and here
is a string of several [see @doe99, pp. 33-35; also
@smit:.#$%&-+?<>~/h04, chap. 1].
@smit:.#$%&-+?<>_/h04, chap. 1].

A parenthetical citation can have a [prenote @doe99] and
a [@smith04 postnote]. The name of the author can be
Expand All @@ -15,7 +15,7 @@ author as follows [-@smith04].

Here is a simple text citation @doe99 and here is a
string of several @doe99 [pp. 33-35; also
@smit:.#$%&-+?<>~/h04, chap. 1]. Here is one with the
@smit:.#$%&-+?<>_/h04, chap. 1]. Here is one with the
name of the author suppressed -@doe99.
>>>
codeSpan: citations
Expand All @@ -37,7 +37,7 @@ BEGIN cite
- suppressAuthor: false
- prenote: also
- postnote: chap.(nbsp)1
- name: smit:.(hash)(dollarSign)(percentSign)(ampersand)-+?<>(tilde)/h04
- name: smit:.(hash)$(percentSign)&-+?<>_/h04
END cite
interblockSeparator
BEGIN cite
Expand Down Expand Up @@ -75,7 +75,7 @@ BEGIN textCite
- suppressAuthor: false
- prenote: also
- postnote: chap.(nbsp)1
- name: smit:.(hash)(dollarSign)(percentSign)(ampersand)-+?<>(tilde)/h04
- name: smit:.(hash)$(percentSign)&-+?<>_/h04
END textCite
BEGIN textCite
- suppressAuthor: true
Expand Down
8 changes: 4 additions & 4 deletions tests/testfiles/lunamark-markdown/citations-no-nbsps.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ propagate through the plain TeX interface.

Here is a simple parenthetical citation [@doe99] and here
is a string of several [see @doe99, pp. 33-35; also
@smit:.#$%&-+?<>~/h04, chap. 1].
@smit:.#$%&-+?<>_/h04, chap. 1].

A parenthetical citation can have a [prenote @doe99] and
a [@smith04 postnote]. The name of the author can be
Expand All @@ -15,7 +15,7 @@ author as follows [-@smith04].

Here is a simple text citation @doe99 and here is a
string of several @doe99 [pp. 33-35; also
@smit:.#$%&-+?<>~/h04, chap. 1]. Here is one with the
@smit:.#$%&-+?<>_/h04, chap. 1]. Here is one with the
name of the author suppressed -@doe99.
>>>
codeSpan: citations
Expand All @@ -37,7 +37,7 @@ BEGIN cite
- suppressAuthor: false
- prenote: also
- postnote: chap. 1
- name: smit:.(hash)(dollarSign)(percentSign)(ampersand)-+?<>(tilde)/h04
- name: smit:.(hash)$(percentSign)&-+?<>_/h04
END cite
interblockSeparator
BEGIN cite
Expand Down Expand Up @@ -75,7 +75,7 @@ BEGIN textCite
- suppressAuthor: false
- prenote: also
- postnote: chap. 1
- name: smit:.(hash)(dollarSign)(percentSign)(ampersand)-+?<>(tilde)/h04
- name: smit:.(hash)$(percentSign)&-+?<>_/h04
END textCite
BEGIN textCite
- suppressAuthor: true
Expand Down

0 comments on commit f0cff9c

Please sign in to comment.