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

Add HTMLTextDocument class #61

Merged
merged 4 commits into from
Oct 10, 2023
Merged

Add HTMLTextDocument class #61

merged 4 commits into from
Oct 10, 2023

Conversation

wch
Copy link
Collaborator

@wch wch commented Oct 4, 2023

The HTMLTextDocument class has a similar purpose to HTMLDocument, except that its contents are loaded from an HTML file.

It is meant to be used with posit-dev/py-shiny#746

This PR also makes it possible change how HTML dependencies are rendered, by setting the following:

htmltools.html_dependency_render_mode = "json"

Normally HTML dependencies are not visible when a Tag/TagList calls .render(). However, if that value is set to "json", then HTML dependencies will be rendered into the document as something like this (note that the JSON has been prettified here, but normally is not):

<script type="application/json" data-html-dependency="">
{
  "name":"strftime",
  "version":"0.9.2",
  "source":{
    "package":"shiny",
    "subdir":"www/shared/strftime/"
  },
  "script":[
    {
      "src":"strftime-min.js"
    }
  ],
  "stylesheet":[    
  ],
  "meta":[    
  ],
  "all_files":false,
  "head":null
}
</script>

Then when the HTML is read in, the HTMLDependency object can be re-created like this:

args = json.loads(x)
dep = HTMLDependency(**args)

htmltools/_core.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@jcheng5 jcheng5 left a comment

Choose a reason for hiding this comment

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

Other than refactoring that duplicated code into a function, LGTM

@wch wch marked this pull request as ready for review October 10, 2023 21:51
@wch wch merged commit e5c9e9d into main Oct 10, 2023
12 checks passed
@wch wch deleted the html-text-doc branch October 10, 2023 21:52
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.

2 participants