halirutan / SE-Editor-Buttons

7 stars 7 forks source link

Reference link formatting. #5

Open rodolfohermans opened 6 years ago

rodolfohermans commented 6 years ago

Three changes in the formatting for references to Mathematica documentations are desirable.

  1. https:// instead of http://
  2. Link URL in the bottom of the text instead of inline
  3. When spaces are selected as input, they should be removed from URL but restored after the link.

Example: given the text

Preamble text link-text epilogue text.

Assume the user selects "link-text " and presses the Ref button (notice the space).

Currently references are formatted like this:

Preamble text [`link-text`](http://reference.wolfram.com/language/ref/link-text.html)epilogue text.

It would be desirable that references are formatted

Preamble text [`link-text`][1] epilogue text. 

  [1]: https://reference.wolfram.com/language/ref/link-text.html
halirutan commented 6 years ago

Changing the URL to https is of course trivial. However, making the links not inline would mean that I have to parse Markdown because I need to count how many other links are already in there to find the correct id (in your case [1]) that I insert.

So your suggestions (2) and (3) means that I have to write JavaScript which I promised myself to prevent under all but most critical circumstances. If you happen to fall under the group of people that don't hate JS as much as I do, please go ahead, make the changes, and send a pull request. I promise to look over it and include this feature.

rodolfohermans commented 6 years ago

I'm not a JavaScript person either. On inspection, it seems the job could be done by calling the function StackExchange Editor uses to add links and images.

https://cdn.sstatic.net/Js/wmd.en.js
addLinkDef(e, t)

with

e= { before:"Lorem ", selection:"ipsum", after:" dolor.", startTag:"", endTag:"", scrollTop:0, }
t = " [999]: https://wolfram.com"

And that does the complicated part of parsing links and ordering tags, but I can't claim to understand everything is going on there and may be more complicated. If I had a code worth sharing I would have committed a version. Thanks anyhow.