imsky / PocketEuler

:heavy_plus_sign: Offline version of Project Euler.
115 stars 11 forks source link

Fix square brackets that are parsed as links #3

Closed imsky closed 8 years ago

imsky commented 10 years ago

Some matrix references are parsed as links, etc

jayvdb commented 8 years ago

By searching the generated html for blob\/master\/[^f] , I find this problem exists in

I also check that there are no occurrences of blob\/master\/f[^i], so that should be the complete list of such problems.

imsky commented 8 years ago

thanks for doing this, i'll convert it into a checklist

jayvdb commented 8 years ago

https://github.com/wooorm/remark-validate-links correctly identifies some of these:

$ remark -u remark-validate-links README.md --no-stdout
README.md
  5212:35-5212:41    warning  Link to unknown file: `n`
  5217:57-5217:63    warning  Link to unknown file: `n`
  5623:21-5623:29    warning  Link to unknown file: `n`
  5628:50-5628:59    warning  Link to unknown file: `35`
  5638:7-5638:16     warning  Link to unknown file: `35`
  5650:33-5650:53    warning  Link to unknown file: `(127+19n)×7%5En`
  9679:9-9679:15     warning  Link to unknown file: `n`
  9680:18-9680:29    warning  Link to unknown file: `625000`
  9682:9-9682:15     warning  Link to unknown file: `n`
  9682:59-9682:72    warning  Link to unknown file: `(2·i-1)!`
  9683:7-9683:14     warning  Link to unknown file: `i!`
  9684:29-9684:38    warning  Link to unknown file: `10%5E3`
  9684:49-9684:58    warning  Link to unknown file: `10%5E9`
  9686:10-9686:20    warning  Link to unknown file: `10%5E18`
  11369:9-11369:15   warning  Link to unknown file: `N`
  11370:9-11370:15   warning  Link to unknown file: `N`
  11370:19-11370:27  warning  Link to unknown file: `p`
  11372:10-11372:21  warning  Link to unknown file: `10%5E14`
  11374:11-11374:19  warning  Link to unknown file: `100`
  11743:18-11743:27  warning  Link to unknown file: `1,%203`
  11746:10-11746:19  warning  Link to unknown file: `1,%203`
  11746:24-11746:33  warning  Link to unknown file: `3,%203`
  11747:43-11747:52  warning  Link to unknown file: `3,%203`
  11770:9-11770:15   warning  Link to unknown file: `k`
  11772:17-11772:25  warning  Link to unknown file: `6`
  11772:29-11772:38  warning  Link to unknown file: `75`
  11772:42-11772:51  warning  Link to unknown file: `89`
  11772:55-11772:65  warning  Link to unknown file: `226`
  11776:5-11776:11   warning  Link to unknown file: `a`
  11776:15-11776:21  warning  Link to unknown file: `b`
  11776:25-11776:31  warning  Link to unknown file: `c`
  11776:35-11776:41  warning  Link to unknown file: `d`
  11779:7-11779:13   warning  Link to unknown file: `a`
  11779:17-11779:23  warning  Link to unknown file: `b`
  11779:27-11779:33  warning  Link to unknown file: `c`
  11779:37-11779:43  warning  Link to unknown file: `d`
  11977:9-11977:15   warning  Link to unknown file: `n`
  11979:5-11979:12   warning  Link to unknown file: `10`
  11980:5-11980:14   warning  Link to unknown file: `2100`
  11981:5-11981:18   warning  Link to unknown file: `2496144`
  11983:37-11983:48  warning  Link to unknown file: `C(n,r)`

⚠ 41 warnings

Those line numbers are problems 211, 230, 383, 444, 460, 461 and 468.

As remark-validate-links doesnt detect all of them, I looked for an error in remark-lint which might help. Unfortunately, it cant smell this problem very accurately.

remark-lint's current output for Problem 149 (which remark-validate-links doesnt detect) shows

  3622:1-3623:12       warning  Don’t use multiple top level headings (3622:1)            no-multiple-toplevel-headings
     3626:1            warning  Remove 1 line before node                                 no-consecutive-blank-lines
  3630:1-3638:52       warning  Code blocks should be fenced                              code-block-style
  3645:21-3645:24      warning  Found reference to undefined definition                   no-undefined-references
  3645:21-3645:24      warning  Use the trailing [] on reference links                    no-shortcut-reference-link
  3645:27-3645:57      warning  Use the trailing [] on reference links                    no-shortcut-reference-link
  3645:27-3645:57      warning  Found reference to undefined definition                   no-undefined-references
  3647:27-3647:30      warning  Use the trailing [] on reference links                    no-shortcut-reference-link
  3647:27-3647:30      warning  Found reference to undefined definition                   no-undefined-references
  3647:35-3647:41      warning  Use the trailing [] on reference links                    no-shortcut-reference-link
  3647:35-3647:41      warning  Found reference to undefined definition                   no-undefined-references
  3647:45-3647:51      warning  Use the trailing [] on reference links                    no-shortcut-reference-link
  3647:45-3647:51      warning  Found reference to undefined definition                   no-undefined-references
  3650:11-3650:15      warning  Found reference to undefined definition                   no-undefined-references
  3650:11-3650:15      warning  Use the trailing [] on reference links                    no-shortcut-reference-link
  3650:31-3650:36      warning  Found reference to undefined definition                   no-undefined-references
  3650:31-3650:36      warning  Use the trailing [] on reference links                    no-shortcut-reference-link
     3660:1            warning  Remove 1 line before node                                 no-consecutive-blank-lines
  3663:1-3664:12       warning  Headings should use atx                                   heading-style
     3663:1            warning  Remove 1 line before node                                 no-consecutive-blank-lines

So, no-shortcut-reference-link and no-undefined-references are likely the two codes we need to enable to prevent new cases arising, however that will involve a lot of changes as those codes cover much more than just these invalid links according to github.

$ remark -u lint README.md 2>&1 | grep '[-]reference' |wc -l
1612

Anyway, patch coming soon for this among with a long series of itemised patches.