Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
b439cacf
Commit
b439cacf
authored
11 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
html2text: Fix leading whitespace after <br>
parent
98018391
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/html2text.php
+28
-21
28 additions, 21 deletions
include/html2text.php
with
28 additions
and
21 deletions
include/html2text.php
+
28
−
21
View file @
b439cacf
...
...
@@ -47,8 +47,9 @@ function convert_html_to_text($html, $width=74) {
// Add the default stylesheet
$elements
->
getRoot
()
->
addStylesheet
(
HtmlStylesheet
::
fromArray
(
array
(
'p'
=>
array
(
'margin-bottom'
=>
1
),
'pre'
=>
array
(
'border-width'
=>
1
,
'white-space'
=>
'pre'
),
'html'
=>
array
(
'white-space'
=>
'pre'
),
# Don't wrap footnotes
'p'
=>
array
(
'margin-bottom'
=>
'1em'
),
'pre'
=>
array
(
'border-width'
=>
'1em'
,
'white-space'
=>
'pre'
),
))
);
$options
=
array
();
...
...
@@ -93,7 +94,7 @@ function identify_node($node, $parent=null) {
case
"hr"
:
return
new
HtmlHrElement
(
$node
,
$parent
);
case
"br"
:
return
"
\n
"
;
return
new
HtmlBrElement
(
$node
,
$parent
)
;
case
"style"
:
$parent
->
getRoot
()
->
addStylesheet
(
new
HtmlStylesheet
(
$node
));
...
...
@@ -189,16 +190,17 @@ class HtmlInlineElement {
foreach
(
$this
->
children
as
$c
)
{
if
(
$c
instanceof
DOMText
)
{
// Collapse white-space
$more
=
$c
->
wholeText
;
switch
(
$this
->
ws
)
{
case
'pre'
:
case
'pre-wrap'
:
$more
=
$c
->
wholeText
;
break
;
case
'
nowrap
'
:
case
'
pre-line
'
:
case
'normal'
:
default
:
$more
=
preg_replace
(
'/\s+/m'
,
' '
,
$
c
->
wholeText
);
case
'pre'
:
case
'pre-wrap'
:
break
;
case
'nowrap'
:
case
'
pre-line
'
:
case
'
normal
'
:
default
:
if
(
$after_block
)
$more
=
ltrim
(
$more
);
$more
=
preg_replace
(
'/\s+/m'
,
' '
,
$
more
);
}
}
elseif
(
$c
instanceof
HtmlInlineElement
)
{
...
...
@@ -207,6 +209,7 @@ class HtmlInlineElement {
else
{
$more
=
$c
;
}
$after_block
=
(
$c
instanceof
HtmlBlockElement
);
if
(
$more
instanceof
PreFormattedText
)
$output
=
new
PreFormattedText
(
$output
.
$more
);
elseif
(
is_string
(
$more
))
...
...
@@ -334,14 +337,19 @@ class HtmlBlockElement extends HtmlInlineElement {
if
(
$c
instanceof
HtmlBlockElement
)
$this
->
min_width
=
max
(
$c
->
getMinWidth
(),
$this
->
min_width
);
elseif
(
$c
instanceof
DomText
)
$this
->
min_width
=
max
(
max
(
array_map
(
'
strlen'
,
explode
(
' '
,
$c
->
wholeText
)))
,
$this
->
min_width
);
$this
->
min_width
=
max
(
max
(
array_map
(
'
mb_strwidth'
,
explode
(
' '
,
$c
->
wholeText
))),
$this
->
min_width
);
}
}
return
$this
->
min_width
;
}
}
class
HtmlBrElement
extends
HtmlBlockElement
{
function
render
(
$width
,
$options
)
{
return
"
\n
"
;
}
}
class
HtmlUElement
extends
HtmlInlineElement
{
function
render
(
$width
,
$options
)
{
$output
=
parent
::
render
(
$width
,
$options
);
...
...
@@ -399,7 +407,6 @@ class HtmlBlockquoteElement extends HtmlBlockElement {
class
HtmlCiteElement
extends
HtmlBlockElement
{
function
render
(
$width
,
$options
)
{
$options
[
'trim'
]
=
false
;
$lines
=
explode
(
"
\n
"
,
ltrim
(
parent
::
render
(
$width
-
3
,
$options
)));
$lines
[
0
]
=
"-- "
.
$lines
[
0
];
// Right justification
...
...
@@ -434,14 +441,15 @@ class HtmlAElement extends HtmlInlineElement {
if
(
$this
->
node
->
getAttribute
(
"name"
)
!=
null
)
{
$output
=
"[
$output
]"
;
}
}
elseif
(
strpos
(
$href
,
'mailto:'
)
===
0
)
{
$href
=
substr
(
$href
,
7
);
$output
=
((
$href
!=
$output
)
?
"
$href
"
:
''
)
.
"<
$output
>"
;
}
elseif
(
mb_strwidth
(
$href
)
>
$width
/
2
)
{
if
(
$href
!=
$output
)
$this
->
getRoot
()
->
addFootnote
(
$output
,
$href
);
$output
=
"[
$output
]"
;
}
else
{
if
(
$href
!=
$output
)
{
$output
=
"[
$output
](
$href
)"
;
}
}
elseif
(
$href
!=
$output
)
{
$output
=
"[
$output
](
$href
)"
;
}
return
$output
;
}
...
...
@@ -453,7 +461,6 @@ class HtmlListElement extends HtmlBlockElement {
function
render
(
$width
,
$options
)
{
$options
[
'marker'
]
=
$this
->
marker
;
$options
[
'trim'
]
=
false
;
return
parent
::
render
(
$width
,
$options
);
}
...
...
@@ -494,7 +501,7 @@ class HtmlCodeElement extends HtmlInlineElement {
function
render
(
$width
,
$options
)
{
$content
=
parent
::
render
(
$width
-
2
,
$options
);
if
(
strpos
(
$content
,
"
\n
"
))
return
"```
\n
"
.
$content
.
"
\n
```"
;
return
"```
\n
"
.
trim
(
$content
)
.
"
\n
```
\n
"
;
else
return
"`
$content
`"
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment