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

Optional markdown support is missing in the 'multi_cell()' and 'write()' methods #171

Closed
pwt opened this issue Jun 22, 2021 · 7 comments
Closed

Comments

@pwt
Copy link

pwt commented Jun 22, 2021

Support for an optional markdown parameter was meant to have been added to the cell(), multi_cell() and write() methods (issue #108, PR #154), to allow rendering of inline bold, italic (etc.) text within a cell.

Support for the markdown parameter is present in the cell() method, but is missing from the multi_cell() and write() methods in FPDF2 v2.4.1.

Support is present in commit 508f39d, which is meant to be part of merged PR #154, but somehow this hasn't made it into the release.

@Lucas-C
Copy link
Member

Lucas-C commented Jun 23, 2021

Thanks for opening this PR to keep track of this.

As mentioned in comment #108 (comment)
adding support for pseudo-Markdown styling in multi_cell() & write() will require some extra work.

Note that this feature is needed in order to properly fix issue #151

I have written some unit tests but I may not have the time to implement this soon.

Pull requests are very welcome!

@pwt
Copy link
Author

pwt commented Jun 23, 2021

Apologies, @Lucas-C -- I'd missed that comment.

(I will take a look to see if I could help with the implementation, but I suspect there'll be too much of an FPDF learning curve for me to contribute efficiently.)

@Lucas-C
Copy link
Member

Lucas-C commented Jun 23, 2021

There are some unit tests to get started:

test_multi_cell_markdown.py.txt

@YeshiNamkhai
Copy link

Hi Lucas-C,
it would great to have it for multi_cell() considering also the template feature, say I may add 'markdown':True to the type TEXT and get the multiline formatted with bold, underline and italics.
Thanks

@Lucas-C
Copy link
Member

Lucas-C commented Jul 7, 2021

Agreed @YeshiNamkhai !

I probably won't tackle this one myself in the near future.
Like most FLOSS projects, fpdf2 is based on volunteer work.
I you really would like this feature, please consider submitting a PR ! 😉

@YeshiNamkhai
Copy link

YeshiNamkhai commented Sep 10, 2021

Well, I have no time to get it work in the last release, but adding few lines already does the job, I 've tested with your example and within my project. So far it's working well with Google fonts and custom templates.

@check_page
def multi_cell(
    self,
    w,
    h=None,
    txt="",
    border=0,
    align="J",
    fill=False,
    split_only=False,
    link="",
    ln=0,
    max_line_height=None,
    #add this:
    markdown=False,
):

then inside the function add markdown=True

        # Explicit line break
        if c == "\n":
            if self.ws > 0:
                self.ws = 0
                self._out("0 Tw")

            if max_line_height and h > max_line_height:
                height = max_line_height
                h -= height
            else:
                height = h
            new_page = self.cell(
                w,
                h=height,
                txt=substr(s, j, i - j),
                border=b,
                ln=2,
                align=align,
                fill=fill,
                link=link,
                #add this:
                markdown=markdown,
            )
            page_break_triggered = page_break_triggered or new_page
            text_cells.append(substr(s, j, i - j))

for every call of self.cell

@Lucas-C
Copy link
Member

Lucas-C commented Sep 10, 2021

I am very surprised that it is actually as easy to implement 😲

When I worked on adding pseudo-Markdown support for FPDF.cell, I expected more complications with multi_cell due to the line breaks.

Anyway, I added your suggestion, thank you @YeshiNamkhai !
https://github.com/PyFPDF/fpdf2/blob/master/CHANGELOG.md#added

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

No branches or pull requests

3 participants