Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7472373
HeadingHandler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
HeadingHandler.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Wikimedia\Parsoid\Html2Wt\DOMHandlers
;
use
Wikimedia\Parsoid\DOM\Element
;
use
Wikimedia\Parsoid\DOM\Node
;
use
Wikimedia\Parsoid\Html2Wt\SerializerState
;
use
Wikimedia\Parsoid\Utils\DiffDOMUtils
;
use
Wikimedia\Parsoid\Utils\WTUtils
;
class
HeadingHandler
extends
DOMHandler
{
/** @var string Heading open/close wikitext (e.g. '===') */
public
$headingWT
;
/**
* @param string $headingWT Heading open/close wikitext (e.g. '===')
*/
public
function
__construct
(
string
$headingWT
)
{
parent
::
__construct
(
true
);
$this
->
headingWT
=
$headingWT
;
}
/** @inheritDoc */
public
function
handle
(
Element
$node
,
SerializerState
$state
,
bool
$wrapperUnmodified
=
false
):
?
Node
{
// For new elements, for prettier wikitext serialization,
// emit a space after the last '=' char.
$space
=
$this
->
getLeadingSpace
(
$state
,
$node
,
' '
);
$state
->
emitChunk
(
$this
->
headingWT
.
$space
,
$node
);
$state
->
singleLineContext
->
enforce
();
if
(
$node
->
hasChildNodes
()
)
{
$state
->
serializeChildren
(
$node
,
null
,
DiffDOMUtils
::
firstNonDeletedChild
(
$node
)
);
}
else
{
// Deal with empty headings
$state
->
emitChunk
(
'<nowiki/>'
,
$node
);
}
// For new elements, for prettier wikitext serialization,
// emit a space before the first '=' char.
$space
=
$this
->
getTrailingSpace
(
$state
,
$node
,
' '
);
$state
->
emitChunk
(
$space
.
$this
->
headingWT
,
$node
);
// Why emitChunk here??
$state
->
singleLineContext
->
pop
();
return
$node
->
nextSibling
;
}
/** @inheritDoc */
public
function
before
(
Element
$node
,
Node
$otherNode
,
SerializerState
$state
):
array
{
if
(
WTUtils
::
isNewElt
(
$node
)
&&
DiffDOMUtils
::
previousNonSepSibling
(
$node
)
&&
!
WTUtils
::
isAnnotationStartMarkerMeta
(
$otherNode
)
)
{
// Default to two preceding newlines for new content
return
[
'min'
=>
2
,
'max'
=>
2
];
}
elseif
(
WTUtils
::
isNewElt
(
$otherNode
)
&&
DiffDOMUtils
::
previousNonSepSibling
(
$node
)
===
$otherNode
)
{
// T72791: The previous node was newly inserted, separate
// them for readability, except if it's an annotation tag
if
(
WTUtils
::
isAnnotationStartMarkerMeta
(
$otherNode
)
)
{
return
[
'min'
=>
1
,
'max'
=>
2
];
}
return
[
'min'
=>
2
,
'max'
=>
2
];
}
else
{
return
[
'min'
=>
1
,
'max'
=>
2
];
}
}
/** @inheritDoc */
public
function
after
(
Element
$node
,
Node
$otherNode
,
SerializerState
$state
):
array
{
return
[
'min'
=>
1
,
'max'
=>
2
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 23, 08:31 (4 d, 1 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8b/34/c40b69e95877acd7de961efd02fb
Default Alt Text
HeadingHandler.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment