Skip to content
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

Better backtick behaviour #16756

Merged

Conversation

MichaelHatherly
Copy link
Member

This extends the backtick syntax in the markdown parser to generalise the "one tick = code" and "two ticks = math" rule to "odd number of ticks = code" and "even number of ticks = math".

Doing this regains the nesting behaviour of backticks and allows both inline code and math to contain arbitrary sequences of backticks so long as enough backticks are used to wrap the code/math.

(Running genstdlib.jl picked up an edgecase that wasn't being parsed correctly before this change.)

@MichaelHatherly MichaelHatherly added the docsystem The documentation building system label Jun 4, 2016
return result === nothing ? nothing : LaTeX(result)
withstream(stream) do
ticks = startswith(stream, r"^(`+)")
result = readuntil(stream, ticks)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this code. startswith doesn't seem to have any methods that take an IO argument, and even if it did it seems like you're passing a boolean value to readuntil

Copy link
Member Author

@MichaelHatherly MichaelHatherly Jun 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The startswith and readuntil aren't from Base, they're different functions specific to the Base.Markdown module. It's definitely confusing and their names should probably be changed when #12740 gets done.

Markdown.startswith returns either nothing or the regex match, in this case the string of opening backticks. Markdown.readuntil then reads up until the matching closing backticks. If the do block returns nothing then withstream resets stream to where it was when entering the block.

@tkelman
Copy link
Contributor

tkelman commented Jun 8, 2016

ready to merge?

@MichaelHatherly
Copy link
Member Author

Yes, should be fine as is, though would be good to know what @hayd and @ararslan were 😕 about before merging.

@hayd
Copy link
Member

hayd commented Jun 8, 2016

My immediate reaction was that it's was kind-of-weird that this would be different to CommonMark, and I wondered whether counting odd-ness for different behavior is going to be surprising.

However, I calmed down a little, though I'm still not completely convinced. (my 😕 stands; 😀 ) But I don't have a counter-proposal.

@StefanKarpinski
Copy link
Sponsor Member

For what it's worth: seems like a decent approach to me.

@tkelman
Copy link
Contributor

tkelman commented Jun 8, 2016

I don't hate the idea of gradually formalizing a "Julia-flavored Markdown" since we're finding things we need that don't exist in established dialects.

This extends the backtick syntax in the markdown parser to
generalise the "one tick = code" and "two ticks = math" rule
to "odd ticks = code" and "even ticks = math".

Doing this regains the nesting behaviour of backticks and allows
both inline code and math to contain arbitrary sequences of backticks
so long as enough backticks are used to wrap the code/math.
@MichaelHatherly
Copy link
Member Author

Thanks for the feedback @hayd. I agree that we shouldn't break from CommonMark if possible, though in this case there doesn't seem to be any agreed upon syntax for inline maths as far as I can see in the spec.

If anyone does come up with a good alternative to this then we can move to that when we find it.

For the moment I'll rerun CI with an additional change (stripping leading and trailing whitespace in inline Code and LaTeX, which is mentioned in the spec and seems to be a good idea to me), and then merge this sometime tomorrow evening.

@StefanKarpinski
Copy link
Sponsor Member

My general thoughts on this is that we should follow CommonMark, but where it doesn't provide a way to do things (e.g. references, definition lists, inline math, math blocks, etc.), we should choose conventions for JuliaMark (or whatever we want to call it) that will render reasonably when interpreted by a standard CommonMark markdown implementation, but which we can interpret with additional meaning. Using even number of backticks for math fits that since it will be rendered as code by implementations that know nothing about the convention, which is a reasonable enough behavior.

@MichaelHatherly MichaelHatherly merged commit a65b334 into JuliaLang:master Jun 9, 2016
@MichaelHatherly MichaelHatherly deleted the mh/better-backtick-behaviour branch June 9, 2016 21:06
@hayd
Copy link
Member

hayd commented Jun 9, 2016

This also deviates a little from commonmark in that:

asda ```block
of code```

is allowed. This surprised me, although most implementations seem to do that.

To confirm, this change is just for inline code? (Not blocks?) In which case, big 👍 .

@MichaelHatherly
Copy link
Member Author

The run-on behaviour has been around since 0.4. I've not used it before either, and was slightly surprised as well.

Yes, it's just inline, not blocks.

@StefanKarpinski
Copy link
Sponsor Member

For blocks I think that opening with ````math` might be better.

@MichaelHatherly
Copy link
Member Author

For display equations, we are using ````math, for example the fft` docs,

julia/base/dft.jl

Lines 389 to 394 in a65b334

```math
\\operatorname{DFT}(A)[k] =
\\sum_{n=1}^{\\operatorname{length}(A)}
\\exp\\left(-i\\frac{2\\pi
(n-1)(k-1)}{\\operatorname{length}(A)} \\right) A[n].
```
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docsystem The documentation building system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants