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

Allow to specify encoding. #662

Closed
ioquatix opened this issue May 4, 2020 · 4 comments
Closed

Allow to specify encoding. #662

ioquatix opened this issue May 4, 2020 · 4 comments
Assignees
Labels

Comments

@ioquatix
Copy link

@ioquatix ioquatix commented May 4, 2020

(raise ::Kramdown::Error, "Missing encoding option on root element"))

In order to convert a small part of the document, I had to copy the encoding:

> Kramdown::Converter::Kramdown.convert(root.children.first)
Traceback (most recent call last):
       16: from /home/samuel/.gem/ruby/2.7.1/gems/utopia-2.15.1/lib/utopia/controller/actions.rb:154:in `block in dispatch'
       15: from /home/samuel/.gem/ruby/2.7.1/gems/utopia-2.15.1/lib/utopia/controller/actions.rb:154:in `instance_exec'
       14: from /home/samuel/Documents/socketry/utopia-project/pages/examples/controller.rb:13:in `block in load_controller_file'
       13: from /home/samuel/Documents/socketry/utopia-project/pages/examples/controller.rb:13:in `find'
       12: from /home/samuel/Documents/socketry/utopia-project/pages/examples/controller.rb:13:in `each'
       11: from /home/samuel/Documents/socketry/utopia-project/lib/utopia/project/base.rb:154:in `examples'
       10: from /home/samuel/Documents/socketry/utopia-project/lib/utopia/project/base.rb:154:in `each_child'
        9: from /home/samuel/Documents/socketry/utopia-project/lib/utopia/project/base.rb:159:in `block in examples'
        8: from /home/samuel/Documents/socketry/utopia-project/lib/utopia/project/base.rb:159:in `new'
        7: from /home/samuel/Documents/socketry/utopia-project/lib/utopia/project/example.rb:44:in `initialize'
        6: from /home/samuel/Documents/socketry/utopia-project/lib/utopia/project/example.rb:59:in `document'
        5: from /home/samuel/Documents/socketry/utopia-project/lib/utopia/project/example.rb:59:in `tap'
        4: from /home/samuel/Documents/socketry/utopia-project/lib/utopia/project/example.rb:72:in `block in document'
        3: from <internal:prelude>:20:in `irb'
        2: from /home/samuel/Documents/socketry/utopia-project/lib/utopia/project/example.rb:5:in `block in document'
        1: from /home/samuel/.gem/ruby/2.7.1/gems/kramdown-2.2.1/lib/kramdown/converter/base.rb:110:in `convert'
Kramdown::Error (Missing encoding option on root element)

> root.children.first.options[:encoding] = root.options[:encoding]

> root.options
=> {:encoding=>#<Encoding:UTF-8>, :location=>1, :options=>{}, :abbrev_defs=>{}, :abbrev_attr=>{}, :footnote_count=>0}

> Kramdown::Converter::Kramdown.convert(root.children.first)
=> ["`utopia-project` easily integrates with GitHub Pages.\n\n", []]

Maybe you could allow:

convert(node, encoding: Encoding::UTF_8)
@gettalong gettalong self-assigned this May 4, 2020
@gettalong
Copy link
Owner

@gettalong gettalong commented May 4, 2020

See

# === :root
#
# [Category] None
# [Usage context] As the root element of a document
# [Content model] Block-level elements
#
# Represents the root of a kramdown document.
#
# The root element contains the following option keys:
#
# :encoding:: When running on Ruby 1.9 this key has to be set to the encoding used for the text
# parts of the kramdown document.
#
# :abbrev_defs:: This key may be used to store the mapping of abbreviation to abbreviation
# definition.
#
# :abbrev_attr:: This key may be used to store the mapping of abbreviation to abbreviation
# attributes.
#
# :options:: This key may be used to store options that were set during parsing of the document.
#
# :footnote_count:: This key stores the number of actually referenced footnotes of the document.
for information on the root element. It not only has the :encoding option but also others.

So if you only want to convert a small part, duplicate the root node and assign the node you want to convert as children, ie. new_root = root.dup; new_root.children = [node].

@ioquatix
Copy link
Author

@ioquatix ioquatix commented May 4, 2020

Should we add documentation on how to do this?

@gettalong gettalong reopened this May 4, 2020
@gettalong
Copy link
Owner

@gettalong gettalong commented May 4, 2020

That is a good idea - will see about it.

@gettalong
Copy link
Owner

@gettalong gettalong commented May 7, 2020

Done

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

No branches or pull requests

2 participants