Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7405201
QuoteHandler.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
QuoteHandler.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\DOMUtils
;
class
QuoteHandler
extends
DOMHandler
{
/** @var string Quote sequence to match as opener/closer */
public
$quotes
;
/**
* @param string $quotes Quote sequence to match as opener/closer
*/
public
function
__construct
(
string
$quotes
)
{
parent
::
__construct
(
false
);
$this
->
quotes
=
$quotes
;
}
/** @inheritDoc */
public
function
handle
(
Element
$node
,
SerializerState
$state
,
bool
$wrapperUnmodified
=
false
):
?
Node
{
if
(
$this
->
precedingQuoteEltRequiresEscape
(
$node
)
)
{
$state
->
emitChunk
(
'<nowiki/>'
,
$node
);
}
$state
->
emitChunk
(
$this
->
quotes
,
$node
);
if
(
$node
->
hasChildNodes
()
)
{
$state
->
serializeChildren
(
$node
);
}
else
{
// Empty nodes like <i></i> or <b></b> need
// a <nowiki/> in place of the empty content so that
// they parse back identically.
$state
->
emitChunk
(
'<nowiki/>'
,
$node
);
}
$state
->
emitChunk
(
$this
->
quotes
,
$node
);
return
$node
->
nextSibling
;
}
private
function
precedingQuoteEltRequiresEscape
(
Element
$node
):
bool
{
// * <i> and <b> siblings don't need a <nowiki/> separation
// as long as quote chars in text nodes are always
// properly escaped -- which they are right now.
//
// * Adjacent quote siblings need a <nowiki/> separation
// between them if either of them will individually
// generate a sequence of quotes 4 or longer. That can
// only happen when either prev or node is of the form:
// <i><b>...</b></i>
//
// For new/edited DOMs, this can never happen because
// wts.minimizeQuoteTags.js does quote tag minimization.
//
// For DOMs from existing wikitext, this can only happen
// because of auto-inserted end/start tags. (Ex: ''a''' b ''c''')
$prev
=
DiffDOMUtils
::
previousNonDeletedSibling
(
$node
);
return
$prev
&&
DOMUtils
::
isQuoteElt
(
$prev
)
&&
(
DOMUtils
::
isQuoteElt
(
DiffDOMUtils
::
lastNonDeletedChild
(
$prev
)
)
||
DOMUtils
::
isQuoteElt
(
DiffDOMUtils
::
firstNonDeletedChild
(
$node
)
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 19:43 (1 d, 4 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
59/87/353d49bfa136c71aefc73382fb3a
Default Alt Text
QuoteHandler.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment