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

Figure out line wrapping #11

Open
ccoupe opened this issue Dec 30, 2016 · 16 comments
Open

Figure out line wrapping #11

ccoupe opened this issue Dec 30, 2016 · 16 comments
Milestone

Comments

@ccoupe
Copy link
Member

ccoupe commented Dec 30, 2016

You may need gfm_quirks and possibly hard_wrap.

Oddly enough, there isn't a lot of google help on how to do that. (other than read and grok the entire kramdown source code). I don't want to be a kramdown internals guru! This doesn't work:

    render_doc = Kramdown::Document.new(File.read(File.join(dir, file)), 
        { :syntax_highlighter => "rouge",
          :syntax_highlighter_opts => { css_class: false, line_numbers: false, inline_theme: "github" },
          cfg: cfg, chapter: sect_nm, input: cfg['input_format'],
          hardwrap: true, paragraph_end:  false
        }
@IanTrudel
Copy link
Collaborator

Kramdown source code reveals it's options. Something along options: { :gfm_quirks }.

@ccoupe
Copy link
Member Author

ccoupe commented Dec 30, 2016

Something along options: { :gfm_quirks }

Grrr. the more correct fix that passes kramdown checks but appears to do nothing useful is

    render_doc = Kramdown::Document.new(File.read(File.join(dir, file)), 
        { :syntax_highlighter => "rouge",
          :syntax_highlighter_opts => { css_class: false, line_numbers: false, inline_theme: "github" },
          cfg: cfg, chapter: sect_nm, input: cfg['input_format'],
          gfm_quirks:  ['hard_wrap']
        }

It's going to be much easier to fix the source md than figure out kramdown's odd logic. I'm going to repeat myself and little more strongly "I am not going to become a kramdown expert" Life is short and I've got enough to do. You've got a real proof of concept. You asked for a list of issues. You got that. Fix one of them.

@IanTrudel
Copy link
Collaborator

Could you provide a simple test case that cause the problem? I need a test case to work on.

@ccoupe
Copy link
Member Author

ccoupe commented Dec 31, 2016

The https://github.com/Shoes3/shoes3/wiki/8.0-New-Widgets file in the wiki is small and has several wrapping issues.

@IanTrudel
Copy link
Collaborator

Have you tried :wrap => word ? Also, would you post a screenshot of the current defective rendering?

@ccoupe
Copy link
Member Author

ccoupe commented Dec 31, 2016

I didn't :wrap ==> word was an option. Highly like that there are two hard line endings in the source.
line-wrap-error

@IanTrudel
Copy link
Collaborator

Now the problem is very clear. Thanks.

@IanTrudel
Copy link
Collaborator

The :wrap option is in the manual. We did have a lengthy conversation about it when it came to Shoes Console. The line endings are not problematic (see screenshot below with display hidden characters turned on in an editor). There are two noticeable problems: 1) lines are cut off, 2) we may have to ignore some end of lines. The Markdown file itself is fine.

image

@IanTrudel
Copy link
Collaborator

Kramdown generates multiple para and call convert_br on each end lines. It should ideally group together lines of a paragraph into one para.

@ccoupe
Copy link
Member Author

ccoupe commented Jan 1, 2017

There is the gkt3 wrap word option. Kramdown however, https://kramdown.gettalong.org/options.html as some odd logic involved with hardwrap - the default is true but there doesn't appear to be anyway to turn if off. gfm_quirks: ['hard_wrap'] is the only thing that passes it's parser.

@IanTrudel
Copy link
Collaborator

IanTrudel commented Jan 1, 2017

Are you using options correctly? According to this test case, it should be :hard_wrap => false (or true). Take a loot at Paragraph End Disable Option: gfm_quirks: 'paragraph_end'.

@IanTrudel
Copy link
Collaborator

IanTrudel commented Jan 1, 2017

hard_wrap: false is working just fine!

image

doc = Kramdown::Document.new(File.read("codespan_block.md"), 
         {input: 'GFM', hard_wrap: false}).to_shoes

@ccoupe
Copy link
Member Author

ccoupe commented Jan 1, 2017

That is better but still not what happens with github/html
better-wrap

@IanTrudel
Copy link
Collaborator

The good news is the generated code is correct. A simple gsub in convert_text seems to do the trick.

image

def convert_text(el)
   %{para("#{el.value.gsub("\n", ' ')}", :margin_left => 0, :margin_right => 0)}
end

@ccoupe
Copy link
Member Author

ccoupe commented Jan 1, 2017

Excellent! I'm tempted to close the issue.

@IanTrudel IanTrudel added this to the 1.0.0 milestone Jan 1, 2017
IanTrudel referenced this issue Jan 1, 2017
* no hook up to the back forward yet, nor to picky.
* baby steps.
@IanTrudel
Copy link
Collaborator

Excellent! I'm tempted to close the issue.

Shall we close this issue? There are few others might also be deserving to be closed.

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

No branches or pull requests

2 participants