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

Move markdown types into their own file. #11421

Closed
wants to merge 1 commit into from

Conversation

hayd
Copy link
Member

@hayd hayd commented May 23, 2015

cc @one-more-minute, I know we discussed this, but after hacking on some other bits, it seems clearer that this is a significant improvement in terms of clearer code / simplicity.... Also, I realised that (after doing this as a proof of concept) it's is going to be difficult to rebase and I don't really want to do it again... so selfishly wanted to punt it as a PR. :)

All this does is reorder methods so that the rendering utils are available when markdown types are defined, e.g. group all the methods related to Code together.

This also adds in a couple of missing methods (which I spotted were missing once in individual files).

Edit: I don't think the linux32 travis failure is me!

@hayd
Copy link
Member Author

hayd commented May 24, 2015

@one-more-minute I rebased and cleaned up a bit. :)

@hayd hayd force-pushed the markdown_refactor branch 2 times, most recently from 2a609fc to 8064256 Compare May 26, 2015 17:56
@hayd
Copy link
Member Author

hayd commented May 26, 2015

rebased!

@tkelman
Copy link
Contributor

tkelman commented May 29, 2015

This should be more consistent about the license headers

@hayd
Copy link
Member Author

hayd commented May 29, 2015

@tkelman Ooops, I've prepended these to all the new files.

@MikeInnes MikeInnes self-assigned this Jul 6, 2015
@tkelman
Copy link
Contributor

tkelman commented Jul 6, 2015

Not a fan of so many tiny, deeply nested files.

@hayd
Copy link
Member Author

hayd commented Jul 6, 2015

I've not changed the depth, but the current naming is incorrect (distinguishing between block and inline - was from an earlier iteration of Markdown.jl).

Note: that the grouping (types with their display methods) is a definite improvement as/and this PR actually uncovered a couple of missing definitions (which were obvious once they were next to each other). So I think we should do some moving here, if there's a better solution I'm open to it...

What's the logic to preferring larger files?

@tkelman
Copy link
Contributor

tkelman commented Jul 6, 2015

It's just a lot of clutter and not a lot of content when files are tiny. Too much editor fiddling and moving back and forth between files, when really these are just part of a markdown parser. There's a non-negligible cognitive and organizational cost per source file, but certainly also a point where files get too large and including too much content that they should be split up. It's subjective, but personally I think the sweet spot is somewhere over 150ish lines to be worth a separate file and somewhere under 1000 to be reasonably well-factored.

For 0.5 or sometime later we should really reconsider whether the markdown parser needs to be in base or if it can be an optional presentation-only feature as an independently-developed module, so code organization questions like this don't really have to be a review burden on either base or the markdown functionality.

@hayd
Copy link
Member Author

hayd commented Jul 7, 2015

I disagree that this is a "review burden", that's not the reason it's not been merged. It's a style thing just like you attested. Talk of moving from base, whilst true seems premature/irrelevant to me as, right now, it's in base... in semantically incorrect files (which caused some confusion for at least me).

non-negligible cognitive and organizational cost per source file

In general this is true, in this case it's not, since after this PR each file contains exactly the same thing (a type, how it's parsed and how it's rendered)... Right now if you want to learn how List is parsed and rendered you need to look in 5+ files.

Like I say, there are alternatives e.g. bring all common types into one file... however, IMO that's just trying to hit the "sweet spot" for the sake if it, rather than for greater code clarity.

Add commented out alternative latex parsing.

latex should not use $$, this is deprecated.

Ensure all new files have the license header.
@MikeInnes
Copy link
Member

FWIW, I like this organisation in general I'm in favour of smaller files rather than thousand-line behemoths. But this does strike me as a little overly fine grained as well.

Style changes like this are always a bit tricky because everyone has a different way of doing it. Rather than making you go through the minutiae of what to put where, maybe it's best if I take a quick go at this myself and put something up to see what you think.

@hayd
Copy link
Member Author

hayd commented Jul 7, 2015

@one-more-minute note I found/added a few missing methods, which are very obvious once they're grouped by type.

a little overly fine grained as well.

I don't disagree, I just don't have a better solution! I'm happy to stick some of these files together myself if that makes sense...

function plain(io::IO, md::BlockQuote)
print(io, "> ")
plain(io, md.content)
end
Copy link
Member

Choose a reason for hiding this comment

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

This should be implemented in a similar way to the term method below otherwise only the first line of the block will have > added. See below:

julia> a = """
       > a
       > 
       > * 1
       > * 2
       >
       > ```
       > aaa
       > ```
       """
"> a\n> \n> * 1\n> * 2\n>\n> ```\n> aaa\n> ```\n"

julia> a |> Markdown.parse |> Markdown.plain |> print
> a

  * 1
  * 2

```
aaa
```

@MichaelHatherly
Copy link
Member

This reorganisation makes it easier to navigate I think, though it might be a good idea to expand the tests prior to doing this to make sure we don't cause any regressions due to shuffling everything around.

(@hayd, some notes inline regarding PR #12130).

@hayd
Copy link
Member Author

hayd commented Jul 13, 2015

It would be nice to confirm, with a test, whether we've hit all of the inline methods or all of the block methods for each type. I agree with your comments from the other PR.

Not sure how much expanding the tests will be sufficient. I recommend just trying out this branch on some complex markdown... :/

This re-org makes it much easier to review this for each type/file... the fact that this passes the tests (in the sense that every parsing function is still defined) as well as me looking carefully at each file (checking it defines each of the inline/block render methods), gives me quite a bit of confidence here.

@kshyatt kshyatt added the docsystem The documentation building system label Sep 6, 2015
@hayd
Copy link
Member Author

hayd commented Sep 16, 2015

Now we're post 0.4 is this worth revisiting (rebasing)? I think we're agreed than having all the methods for each type in the same file would make code clearer BUT having files just including a type and their methods (the current state of this PR) is too finely-grained... so I'm not sure what the best compromise.

@hayd
Copy link
Member Author

hayd commented Sep 17, 2015

Perhaps a compromise is to remove some of the directory structure for flavors (of CommonMark, IJulia, Github) will make this cleaner (and less nested than before)... Even if the filesizes remained small (one for each type + parsing + rendering). I'm not sure what the purpose of supporting multiple @flavors was (this was brought up elsewhere recently), but I don't think the current directory structure adds value for it.

So it would be:

Markdown/
  render/
  parse/
  blockquote.jl
  bold.jl
  ...
  Markdown.jl

@jakebolewski
Copy link
Member

I don't think this is necessary.

@hayd
Copy link
Member Author

hayd commented Sep 17, 2015

Even for the autolinks code (with no additional rendering) I needed to modify 6 files, for a more usual type e.g. horizontal rule it's 8 (#10483). And it's really tricky to spot missing methods.

This refactor is not necessary but it would make reading/editing/maintaining significantly easier.

@tkelman
Copy link
Contributor

tkelman commented Sep 17, 2015

Your proposal of dropping the final flavor level of hierarchy sounds reasonable to me, though I haven't been working on this code.

@StefanKarpinski StefanKarpinski added this to the 0.5.x milestone Sep 13, 2016
@StefanKarpinski StefanKarpinski added status:help wanted Indicates that a maintainer wants help on an issue or pull request and removed status:help wanted Indicates that a maintainer wants help on an issue or pull request labels Oct 27, 2016
@JeffBezanson
Copy link
Sponsor Member

Has been moved to stdlib, so less necessary and would need to be redone.

@JeffBezanson JeffBezanson removed this from the 0.5.x milestone May 21, 2018
@hayd hayd deleted the markdown_refactor branch May 21, 2018 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docsystem The documentation building system status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants