voku / html2text Goto Github PK
View Code? Open in Web Editor NEWThis project forked from mtibben/html2text
:memo: Html2Text - Convert HTML to formatted plain text, e.g. for text mails.
License: Other
This project forked from mtibben/html2text
:memo: Html2Text - Convert HTML to formatted plain text, e.g. for text mails.
License: Other
thank you for your libraries! just awesome
Hi,
Firstly wanted to say thanks for your great work in extending the use of this library!
My question is about ordered lists: I would like to be able to display them as follows:
instead of using asterisks for each list item. Is this possible?
It returns just Array
on a page, instead of a text version of the text on URL provided.
There is a LICENSE file, which is a GPL v. 2, plus some badly formatted extra advertising clause talking about commands and stuff.
Looks like something got very badly copy-pasted carelessly.
I strongly suggest against any of that:
print (new Html2Text('<P>Test string</P>'))->getText();
prints nothing while
print (new Html2Text('<p>Test string</p>'))->getText()
prints Test string
as expected.
The reason for that is in \voku\Html2Text\Html2Text::pregCallback
.
$matches['element']
is initially converted to lowercase with
$element = \strtolower($matches['element']);
but the lowercase version is not used in the switch statement or to match headings:
protected function pregCallback(array $matches): string
{
// init
$element = \strtolower($matches['element']);
switch ($matches['element']) { // Case sensitive
case 'p':
// Replace newlines with spaces.
$para = \str_replace("\n", ' ', $matches['value']);
// Add trailing newlines for this paragraph.
return "\n\n" . $para . "\n\n";
...
...
}
// h1 - h6
if (\preg_match('/h[123456]/', $matches['element'])) { // Case sensitive
return $this->convertElement($matches['value'], $matches['element']);
}
I don't understand why pregCallback
returns an empty string as last line.
Shouldn't the code always know how to handle the $matches['element']
that ends up in pregCallback
?
Wouldn't it be better to throw an exception in case there is no handling available for a match $matches['element']
or return $matches['value'] ?? ''
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.