gboncoffee.dev.br

My kawaii website.
Log | Files | Refs | LICENSE

orgize-emphasis-next-to-quotes.md (3808B)


      1 # orgize: emphasis markers next to double quotes are not recognized
      2 
      3 Status: worked around in the site, patch to be sent upstream to
      4 [orgize-ng](https://github.com/szaffarano/orgize) (maintained fork of
      5 [orgize](https://github.com/PoiScript/orgize), which has the same bug).
      6 
      7 ## The problem
      8 
      9 Org accepts emphasis markup right after an opening double quote and right
     10 before a closing one, so both of these are valid Org:
     11 
     12 ```org
     13 "I don't like ~curl | sh~"
     14 ("/Instruction Set Architecture/")
     15 ```
     16 
     17 Emacs exports them as `"I don't like <code>curl | sh</code>"` and
     18 `("<i>Instruction Set Architecture</i>")`. orgize doesn't recognize the
     19 markup and leaves the markers in the text: `"I don't like ~curl | sh~"`.
     20 
     21 ## What Org does
     22 
     23 The characters allowed around emphasis are defined by
     24 `org-emphasis-regexp-components` (in `org.el`). Its default value is:
     25 
     26 | Part | Default | Meaning |
     27 |---|---|---|
     28 | pre | `-[:space:]('"{` | characters allowed right before the opening marker |
     29 | post | `-[:space:].,:!?;'")}\[` | characters allowed right after the closing marker |
     30 
     31 So `"` is valid both before and after an emphasized text, and `'` is also
     32 valid before it.
     33 
     34 ## What orgize does
     35 
     36 In orgize-ng 0.11.0, `src/syntax/emphasis.rs`:
     37 
     38 ```rust
     39 fn validate_marker(pos: usize, text: Input) -> bool {
     40     if text.as_bytes()[pos - 1].is_ascii_whitespace() {
     41         false
     42     } else if let Some(post) = text.as_bytes().get(pos + 1) {
     43         b" \t\r\n-.,;:!?')}[".contains(post)
     44     } else {
     45         true
     46     }
     47 }
     48 
     49 pub fn verify_pre(input: &str) -> bool {
     50     if input.is_empty() {
     51         return true;
     52     }
     53     matches!(
     54         input.as_bytes()[input.len() - 1],
     55         b'\t' | b' ' | b'-' | b'(' | b'{' | b'\\' | b'"' | b'\r' | b'\n'
     56     )
     57 }
     58 ```
     59 
     60 Compared to Org's defaults:
     61 
     62 - `validate_marker` (post) is missing `"`. This is the bug that breaks the
     63   examples above: the closing marker is followed by `"`, so it's rejected.
     64 - `verify_pre` (pre) is missing `'`, so `'/word/'` doesn't work either.
     65 - `verify_pre` accepts `\`, which isn't in Org's defaults. Probably
     66   intentional (or harmless), but worth checking when sending the patch.
     67 
     68 The original orgize (0.10.0-alpha.10) has the same lists. orgize 0.9.0 has
     69 a similar problem in `src/elements/emphasis.rs` (`validate_marker` without
     70 `"`).
     71 
     72 A zero-width space between the marker and the quote doesn't work around it,
     73 since it isn't in either list.
     74 
     75 ## Proposed fix
     76 
     77 ```diff
     78 --- a/src/syntax/emphasis.rs
     79 +++ b/src/syntax/emphasis.rs
     80 @@ fn validate_marker(pos: usize, text: Input) -> bool {
     81 -        b" \t\r\n-.,;:!?')}[".contains(post)
     82 +        b" \t\r\n-.,;:!?'\")}[".contains(post)
     83 @@ pub fn verify_pre(input: &str) -> bool {
     84 -        b'\t' | b' ' | b'-' | b'(' | b'{' | b'\\' | b'"' | b'\r' | b'\n'
     85 +        b'\t' | b' ' | b'-' | b'(' | b'{' | b'\\' | b'"' | b'\'' | b'\r' | b'\n'
     86 ```
     87 
     88 Tests to add alongside the existing ones in `emphasis.rs`:
     89 
     90 ```rust
     91 // Closing marker followed by a double quote.
     92 assert!(code_node(("~curl | sh~\"", config).into()).is_ok());
     93 assert!(italic_node(("/word/\")", config).into()).is_ok());
     94 ```
     95 
     96 And a parse-level test, so the pre side is covered too:
     97 
     98 ```rust
     99 let org = Org::parse("He said \"~curl | sh~\" and '/left/'.");
    100 assert_eq!(org.first_node::<Code>().unwrap().text(), "curl | sh");
    101 assert!(org.first_node::<Italic>().is_some());
    102 ```
    103 
    104 (Adjust to the test helpers the crate uses; the exact accessor names may
    105 differ.)
    106 
    107 ## Workaround in the site
    108 
    109 Until the fix is released, the two affected spots use an inline HTML export
    110 snippet instead of Org markup:
    111 
    112 - `posts/fuck-off-with-your-curl-sh.org`: `"I don't like @@html:<code>curl | sh</code>@@"`
    113 - `posts/zen-traducao.org`: `("@@html:<i>Instruction Set Architecture</i>@@")`
    114 
    115 Once orgize-ng has the fix, these can go back to `~curl | sh~` and
    116 `/Instruction Set Architecture/`.