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

[HTML] Introducing tag_indents & tag_styles #1124

Merged
merged 6 commits into from
Feb 28, 2024
Merged

[HTML] Introducing tag_indents & tag_styles #1124

merged 6 commits into from
Feb 28, 2024

Conversation

Lucas-C
Copy link
Member

@Lucas-C Lucas-C commented Feb 27, 2024

This is a follow-up of #1066 that also provides the feature requested in #1074

Checklist:

  • The GitHub pipeline is OK (green), meaning that both pylint (static code analyzer) and black (code formatter) are happy with the changes of this PR.

  • A unit test is covering the code added / modified by this PR

  • This PR is ready to be merged

  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder

  • A mention of the change is present in CHANGELOG.md

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

Documentation added to docs/HTML.md:

Styling HTML tags globally

The style of several HTML tags (<a>, <blockquote>, <code>, <pre>, <li>, <h1>, <h2>, <h3>...) can be set globally, for the whole HTML document, by passing tag_styles to FPDF.write_html():

from fpdf import FPDF, FontFace

pdf = FPDF()
pdf.add_page()
pdf.write_html("""
  <h1>Big title</h1>
  <section>
    <h2>Section title</h2>
    <p>Hello world!</p>
  </section>
""", tag_styles={
    "h1": FontFace(color=(148, 139, 139), size_pt=32),
    "h2": FontFace(color=(148, 139, 139), size_pt=24),
})
pdf.output("html_styled.pdf")

Similarly, the indentation of several HTML tags (<blockquote>, <dd>, <li>) can be set globally, for the whole HTML document, by passing tag_indents to FPDF.write_html():

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.write_html("""
  <dl>
      <dt>Term</dt>
      <dd>Definition</dd>
  </dl>
""", tag_indents={"dd": 5})
pdf.output("html_dd_indented.pdf")

@Lucas-C Lucas-C changed the title Allow users to set HTML links colors [HTML] Introducing tag_indents & tag_styles Feb 27, 2024
This was referenced Feb 27, 2024
@Lucas-C Lucas-C force-pushed the html_tag_styles branch 2 times, most recently from edeb0b3 to ffde695 Compare February 27, 2024 21:37
@Lucas-C
Copy link
Member Author

Lucas-C commented Feb 27, 2024

@gmischler & @andersonhc: could you please review this PR?

It introduces some two new "structuring" parameters to HTML2FPDF, so I'd be happy to get your feedback on that 😊

@Lucas-C Lucas-C force-pushed the html_tag_styles branch 2 times, most recently from ce824fc to 400ed4f Compare February 28, 2024 07:55
@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 88.07339% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 93.34%. Comparing base (e85ec4e) to head (dfe0f5b).

❗ Current head dfe0f5b differs from pull request most recent head 103708e. Consider uploading reports for the commit 103708e to get more accurate results

Files Patch % Lines
fpdf/html.py 86.17% 5 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1124      +/-   ##
==========================================
- Coverage   93.42%   93.34%   -0.09%     
==========================================
  Files          30       30              
  Lines        9130     9179      +49     
  Branches     2071     2089      +18     
==========================================
+ Hits         8530     8568      +38     
- Misses        371      374       +3     
- Partials      229      237       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Lucas-C Lucas-C force-pushed the html_tag_styles branch 2 times, most recently from cd96422 to ff8165d Compare February 28, 2024 17:20
@Lucas-C Lucas-C force-pushed the html_tag_styles branch 2 times, most recently from 35812d1 to 9b5836b Compare February 28, 2024 18:14
Copy link
Collaborator

@gmischler gmischler left a comment

Choose a reason for hiding this comment

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

Looks ok, adding flexibility without making them much more complicated.

fpdf/html.py Show resolved Hide resolved
@Lucas-C
Copy link
Member Author

Lucas-C commented Feb 28, 2024

Looks ok, adding flexibility without making them much more complicated.

Thank you for the feedback!

Merging this now.

@Lucas-C Lucas-C merged commit b7e9b11 into master Feb 28, 2024
13 checks passed
@Lucas-C Lucas-C deleted the html_tag_styles branch February 28, 2024 23:25
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.

4 participants