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

RFC Markdown sections #9853

Closed
wants to merge 2 commits into from
Closed

RFC Markdown sections #9853

wants to merge 2 commits into from

Conversation

hayd
Copy link
Member

@hayd hayd commented Jan 20, 2015

This is on the top of #9852 (whitespace changes to Markdown) so please excuse the large diff in the first commit.

This adds methods for sections and subsections in the terminal, as a partial fix for #9850.

julia> Base.Markdown.parse("#Title")
                                                           Title
                                                          -=====-

julia> Base.Markdown.parse("##Section")
                                                          Section
                                                         -–––––––-

julia> Base.Markdown.parse("###Subsection")
Subsection
––––––––––

I don't feel strongly about what these actually are (very happy to amend), but thought I would put this out there.

cc @one-more-minute

@ivarne
Copy link
Member

ivarne commented Jan 20, 2015

I merged #9852, so hopefully the diff will be smaller soon. Maybe github needs a forced push in order to get clean up this PR?

@hayd hayd force-pushed the markdown_sections branch from 5eb3a85 to 897fa0b Compare January 20, 2015 16:58
@hayd
Copy link
Member Author

hayd commented Jan 20, 2015

@ivarne rebased. (Thanks for merging #9852!)

@hayd
Copy link
Member Author

hayd commented Jan 20, 2015

TBH/my 2 cents: I don't particularly like/find it hard to read centered... personally I would prefer if they were all left-aligned. e.g.

julia> Base.Markdown.parse("#Title")
 Title
-=====-

julia> Base.Markdown.parse("##Section")
 Section
-–––––––-

julia> Base.Markdown.parse("###Subsection")
 Subsection
------------

@nalimilan
Copy link
Member

I agree left-aligned is more readable.

@timholy
Copy link
Member

timholy commented Jan 21, 2015

I also like left-aligned.

@MichaelHatherly
Copy link
Member

+1 for left-aligned.

@MikeInnes MikeInnes self-assigned this Jan 22, 2015
@MikeInnes
Copy link
Member

:( Well, I'm a bit sad to see my nice centred titles going, but the community giveth and the community taketh away. Feel free to left-align everything.

Personally I also think

 Title
=======

looks nicer than

 Title
-=====-

@jiahao
Copy link
Member

jiahao commented Jan 22, 2015

Centrism is so 1980s.

@hayd
Copy link
Member Author

hayd commented Jan 22, 2015

Updated, it's now a little simpler (as @one-more-minute suggested):

julia> Markdown.parse("# Title")
 Title
=======

julia> Markdown.parse("## Section")
 Section
–––––––––

julia> Markdown.parse("### SubSection")
 SubSection
------------

# Note above can lose bold formatting
# ensure at least that the underline is bold
with_output_format(:bold, io) do io
println(io, string(char) ^ min(1 + n, columns))
Copy link
Member

Choose a reason for hiding this comment

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

I see what you're going for here but I think it would look cleaner to do min(2+length(text), columns÷2).

Copy link
Member Author

Choose a reason for hiding this comment

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

That would do something different. This does the following for multiline titles:

 This title is longer that the column width
 so underline last line
========================

I think using div here would get some surprising/unstable/ugly behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but it leads to weird behaviour if the last line happens to be short:

 This title is longer that the column width so underline last
 line
======

which looks a bit off to me, or even actively confusing since it's less obvious that it's a title.

The div code makes things more stable because the length of the underline will always be halfway across the terminal for long titles (and behaves the same way for short ones):

 This title is longer that the column width so underline last
 line
====================================

(Now I think about it, 2/3s the way across might look better, but that's a detail)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm kinda "meh" on both (I think both can look weird in some cases) but personally I prefer my way! :p

Edit (pressed enter too early): I wonder if anyone else has solved this problem (of what looks nicer).

Copy link
Member

Choose a reason for hiding this comment

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

Well, it looks quite nice when it's all centred ;)

How about a mix of both – as long as the last line, but no shorter than 2/3s, for example?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, it looks quite nice when it's all centred ;)

true! ok, i'm gonna try either 1/2 or 1/3, see what looks "nicest", and we can change it later.

@elextr
Copy link

elextr commented Jan 25, 2015

Some issues on underlining of titles that have bitten in the past on other projects:

  1. non-monospaced fonts, and more and more terminals are coming with those
  2. even in monospaced fonts, count graphemes, not code points, to account for composing characters
  3. varying width unicode chars

Unfortunately libmojibake doesn't seem to handle the last two

Whilst this doesn't say "don't try to align underlines" just be aware that they won't work in some cases.

@hayd
Copy link
Member Author

hayd commented Jan 25, 2015

@elextr IMO if you use a non-monospace font you're going to have a bad terminal experience.

this doesn't say "don't try to align underlines" just be aware that they won't work in some cases.

+1.

@hayd hayd force-pushed the markdown_sections branch from a3ad81c to 749cfb9 Compare January 25, 2015 20:43
@hayd
Copy link
Member Author

hayd commented Jan 25, 2015

@one-more-minute hopefully this last commit is a nice compromise :) force pushed a rebase over your latest commits (re boldness), they work great!

@hayd
Copy link
Member Author

hayd commented Jan 31, 2015

bump!

@ViralBShah
Copy link
Member

Could you squash the commits?

hayd added 2 commits January 31, 2015 08:03
left align sections

simplify markdown header underlines

if md header runs over multiple lines ensure at least 1/3 columns
@hayd hayd force-pushed the markdown_sections branch from 3d79c79 to da1242b Compare January 31, 2015 16:04
MikeInnes added a commit that referenced this pull request Jan 31, 2015
@MikeInnes MikeInnes closed this Jan 31, 2015
@hayd
Copy link
Member Author

hayd commented Jan 31, 2015

Excellent! Thanks for merging @one-more-minute, squashed one but ran out of time this morning.

@MikeInnes
Copy link
Member

No problem, thanks for the PR!

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

Successfully merging this pull request may close these issues.

9 participants