-
-
Notifications
You must be signed in to change notification settings - Fork 169
Adding support for subscript, highlighted and underlined text #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
49c7517
bb6ff75
b3d9a4f
d45a960
ebd4536
b86eaf0
a37b2bd
b60b5a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,13 +145,20 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> { | |
| s.special_chars[b'~' as usize] = true; | ||
| s.skip_chars[b'~' as usize] = true; | ||
| } | ||
| if options.extension.subscript { | ||
| s.special_chars[b'~' as usize] = true; | ||
| } | ||
| if options.extension.superscript { | ||
| s.special_chars[b'^' as usize] = true; | ||
| } | ||
| #[cfg(feature = "shortcodes")] | ||
| if options.extension.shortcodes { | ||
| s.special_chars[b':' as usize] = true; | ||
| } | ||
| if options.extension.highlight { | ||
| s.special_chars[b'=' as usize] = true; | ||
| s.skip_chars[b'=' as usize] = true; | ||
| } | ||
| for &c in &[b'"', b'\'', b'.', b'-'] { | ||
| s.smart_chars[c as usize] = true; | ||
| } | ||
|
|
@@ -210,10 +217,9 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> { | |
| )) | ||
| } | ||
| } | ||
| '~' if self.options.extension.strikethrough => Some(self.handle_delim(b'~')), | ||
| '^' if self.options.extension.superscript && !self.within_brackets => { | ||
| Some(self.handle_delim(b'^')) | ||
| } | ||
| '~' if (self.options.extension.subscript && !self.within_brackets) || self.options.extension.strikethrough => Some(self.handle_delim(b'~')), | ||
| '^' if self.options.extension.superscript && !self.within_brackets => Some(self.handle_delim(b'^')), | ||
| '=' if self.options.extension.highlight => Some(self.handle_delim(b'=')), | ||
| _ => { | ||
| let endpos = self.find_special_char(); | ||
| let mut contents = self.input[self.pos..endpos].to_vec(); | ||
|
|
@@ -337,10 +343,11 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> { | |
| let ix = match c.delim_char { | ||
| b'~' => 0, | ||
| b'^' => 1, | ||
| b'"' => 2, | ||
| b'\'' => 3, | ||
| b'_' => 4, | ||
| b'*' => 5 + (if c.can_open { 3 } else { 0 }) + (c.length % 3), | ||
| b'=' => 2, | ||
| b'"' => 3, | ||
| b'\'' => 4, | ||
| b'_' => 5, | ||
| b'*' => 6 + (if c.can_open { 2 } else { 0 }) + (c.length % 3), | ||
bismitpanda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _ => unreachable!(), | ||
| }; | ||
|
|
||
|
|
@@ -387,8 +394,9 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> { | |
| // both get passed. | ||
| if c.delim_char == b'*' | ||
| || c.delim_char == b'_' | ||
| || (self.options.extension.strikethrough && c.delim_char == b'~') | ||
| || ((self.options.extension.strikethrough || self.options.extension.subscript) && c.delim_char == b'~') | ||
| || (self.options.extension.superscript && c.delim_char == b'^') | ||
| || (self.options.extension.highlight && c.delim_char == b'=') | ||
| { | ||
| if opener_found { | ||
| // Finally, here's the happy case where the delimiters | ||
|
|
@@ -837,13 +845,6 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> { | |
| opener_num_chars -= use_delims; | ||
| closer_num_chars -= use_delims; | ||
|
|
||
| if self.options.extension.strikethrough | ||
| && opener_char == b'~' | ||
| && (opener_num_chars != closer_num_chars || opener_num_chars > 0) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect (though haven't checked) this will cause spec failure with this example. The spec requires three or more tildes to not generate a strikethrough; since we've already subtracted
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If subscript and strikethrough, both are enabled, it will be a subscript as well as a strikethrough\ like in cases of italics and bolds. Considering this, I removed the condition.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding and additional if (self.options.extension.strikethrough
&& opener_char == b'~'
&& (opener_num_chars != closer_num_chars || opener_num_chars > 0))
&& !self.options.extension.subscript
{
return None;
} |
||
| { | ||
| return None; | ||
| } | ||
|
|
||
| opener | ||
| .inl | ||
| .data | ||
|
|
@@ -870,9 +871,13 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> { | |
| } | ||
|
|
||
| let emph = self.make_inline( | ||
| if self.options.extension.strikethrough && opener_char == b'~' { | ||
| if self.options.extension.highlight && opener_char == b'=' && use_delims == 2 { | ||
| NodeValue::Highlight | ||
| } else if self.options.extension.strikethrough && opener_char == b'~' && use_delims == 2 { | ||
| NodeValue::Strikethrough | ||
| } else if self.options.extension.superscript && opener_char == b'^' { | ||
| } else if self.options.extension.subscript && opener_char == b'~' && use_delims == 1 { | ||
| NodeValue::Subscript | ||
| } else if self.options.extension.superscript && opener_char == b'^' && use_delims == 1 { | ||
| NodeValue::Superscript | ||
| } else if use_delims == 1 { | ||
| NodeValue::Emph | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn highlight() { | ||
| html_opts!( | ||
| [extension.highlight], | ||
| concat!("This is an ==important== word.\n"), | ||
| concat!("<p>This is an <mark>important</mark> word.</p>\n"), | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn subscript() { | ||
| html_opts!( | ||
| [extension.subscript], | ||
| concat!("Water is H~2~O.\n"), | ||
| concat!("<p>Water is H<sub>2</sub>O.</p>\n"), | ||
| ); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.