討論區: 公開討論 (Thread #19941)

pc2m_remainを使ってもdiv内のinline style属性が消える (2008-09-17 17:50 by 匿名 #38889)

<div style="background:red" align="center"> のようなインラインのstyle属性をそのまま出力したくて、pc2m_remain で囲んでも、style="" が削除されて以下の出力されます。
<div align="center">

pc2m.phpのソースを少し見てみました。2000行あたりの以下の時点で既にstyle=""は削られています。

if (preg_match_all('/<!--pc2m_remain-->(.+?)<!--\/pc2m_remain-->/si', $_content, $matches)) {

そこからはどう追えばいいのかがわかりませんでした。
アドバイス等頂けますでしょうか?

回覆 #38889×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) 登入

RE: pc2m_remainを使ってもdiv内のinline style属性が消える (2008-09-19 23:02 by ucb #38931)

HTMLの整形処理(そのしばらく前の $parser->parse($_content); となってる箇所あたり)でSTYLE属性は消え失せます。整形処理のルールファイル(FormatRule.inc.php)にそう書いてるので。

■対処1:STYLE属性を残すようにルールファイルを書き直す。

FormatRule.inc.phpはPC2M専用で、多くの要素と属性を削除してしまうようになってますが、以下からダウンロードできるオリジナルのHTMLParserクラスのアーカイブに入ってるサンプルのルールファイル(xhtml1-transitional_dtd.inc.php)はXHTML 1.0の要素と属性を網羅してるので、両者を参照しながら書き直していただければよいかと。
http://www.rcdtokyo.com/ucb/contents/i000799.php

まあ、必要な要素(divだけですかね?)の「attributes」配列に'style'を加えてやればいいだけの筈なんですけど。

■対処2:「~remain」の保存が整形処理の前になるようにpc2m.phpを書き直す(結構面倒だと思うので推奨しません)

覚えてないんですけど(笑)、たぶんinvalidなHTMLが~remainで括られてるとあとあと面倒なので先に整形処理を済ませちゃってると思うので、そうでなければ支障はないと思うんですよねー。
回覆: #38889

回覆 #38931×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) 登入

RE: pc2m_remainを使ってもdiv内のinline style属性が消える (2008-09-20 09:19 by 匿名 #38942)

FormatRule.inc.php 18行目あたりを以下のように変更しても style属性は消えてしまいます。

'div' => array(
'type' => 'block',
'children' => array('#PCDATA', 'br'),
// 'attributes' => array(),
'attributes' => array('style'),
),

もうちょっと調べてみます。
回覆: #38889

回覆 #38942×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) 登入

RE: pc2m_remainを使ってもdiv内のinline style属性が消える (2008-09-22 20:13 by ucb #38968)

それはFormatRule.inc.phpではなく、FormatRule_Text.inc.phpですね(こっちは「写」モード用で、一部を除く全てのタグと属性を削ぎ落とす設定)

FormatRule.inc.phpの、たぶん41行目あたり

'div' => array(
'type' => 'block',
'children' => array('#PCDATA', 'p', ~略
'attributes' => array('align')
),

のattributesのところを

'attributes' => array('align', 'style')

とすれば良い筈です。
回覆: #38942

回覆 #38968×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) 登入

[]RE: pc2m_remainを使ってもdiv内のinline style属性が消える (2008-09-23 17:34 by 匿名 #38979)

できました。
単純なミスですみませんでした。
回覆: #38889

回覆 #38979×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) 登入