Shoes3 / ebook

An interactive eBook written in Shoes.
2 stars 0 forks source link

Figure out line wrapping #11

Open ccoupe opened 7 years ago

ccoupe commented 7 years ago

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 commented 7 years ago

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

ccoupe commented 7 years ago

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 commented 7 years ago

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

ccoupe commented 7 years ago

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

IanTrudel commented 7 years ago

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

ccoupe commented 7 years ago

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

IanTrudel commented 7 years ago

Now the problem is very clear. Thanks.

IanTrudel commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

IanTrudel commented 7 years ago

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 commented 7 years ago

Excellent! I'm tempted to close the issue.

IanTrudel commented 7 years ago

Excellent! I'm tempted to close the issue.

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