private void Para_stack_end(int cur_pos) { // MW: $output .= $paragraphStack; switch (para_stack) { case Para_stack_none: break; case Para_stack_bgn: prv_para.Para_end_(Xop_para_tkn.Tid_none).Para_bgn_(Xop_para_tkn.Tid_para); break; // '<p>' case Para_stack_mid: prv_para.Para_end_(Xop_para_tkn.Tid_para).Para_bgn_(Xop_para_tkn.Tid_para); break; // '</p><p>' } }
private void Prv_para_end() { // MW: closeParagraph(); // following switch is equivalent to: // MW: if ( $this->mLastSection != '' ) // MW: $result = '</' . $this->mLastSection . ">\n"; switch (cur_mode) { case Mode_none: return; case Mode_pre: prv_para.Para_end_(Xop_para_tkn.Tid_pre); break; case Mode_para: prv_para.Para_end_(Xop_para_tkn.Tid_para); break; } // in_pre = false; // MW: $this->mInPre = false; cur_mode = Mode_none; // MW: $this->mLastSection = ''; }
private void Process_block(Xop_xnde_tag tag, boolean bgn, boolean end) { if (prv_ws_bgn > 0) { prv_para.Space_bgn_(prv_ws_bgn); prv_ws_bgn = 0; } block_is_bgn_xnde = bgn; block_is_end_xnde = end; switch (tag.Id()) { case Xop_xnde_tag_.Tid_blockquote: if (bgn) block_is_bgn_blockquote = true; if (end) block_is_end_blockquote = true; break; } }
private void Prv_para_bgn(byte mode) { if (prv_para != null) prv_para.Para_bgn_(mode); }
public void Process_nl( Xop_ctx ctx, Xop_root_tkn root, byte[] src, int bgn_pos, int cur_pos) { // REF.MW:Parser.php|doBlockLevels Dd_clear(ctx); if (block_is_bgn_xnde || block_is_end_xnde) { para_stack = Para_stack_none; // MW: $paragraphStack = false; Prv_para_end(); // MW: $output .= $this->closeParagraph() if (block_is_bgn_blockquote && !block_is_end_blockquote) // MW: if ( $preOpenMatch and !$preCloseMatch ) in_blockquote = true; // MW: $this->mInPre = true; else in_blockquote = false; // XO: turn off blockquote else following para / nl won't work; // w:Snappy_(software); DATE:2014-04-25 in_block = !block_is_end_xnde; // MW: $inBlockElem = !$closematch; } else if (!in_block && !in_blockquote) { // MW: elseif ( !$inBlockElem && !$this->mInPre ) { boolean line_is_ws = Line_is_ws(src, bgn_pos); if (prv_ws_bgn > 0 && (cur_mode == Mode_pre || !line_is_ws)) { // MW: if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === // 'pre' || trim( $t ) != '' ) ) { if (cur_mode != Mode_pre) { // MW: if ( $this->mLastSection !== 'pre' ) { para_stack = Para_stack_none; // MW: $paragraphStack = false; prv_para.Space_bgn_( prv_ws_bgn - 1); // -1 to ignore 1st "\s" in "\n\s"; note that prv_ws_bgn only includes // spaces, so BOS doesn't matter; DATE:2014-04-14 Prv_para_end(); Prv_para_bgn(Xop_para_tkn.Tid_pre); // MW: $output .= $this->closeParagraph() . '<pre>'; cur_mode = Mode_pre; // MW: $this->mLastSection = 'pre'; } else { // already in pre if (line_is_ws) { // line is entirely ws int next_char_pos = prv_nl_pos + 2; // "\n\s".length if (next_char_pos < src.length // bounds check && src[next_char_pos] == Byte_ascii.Nl // is "\n\s\n"; i.e.: "\n" only ) { ctx.Subs_add( root, ctx.Tkn_mkr() .Bry_raw( bgn_pos, bgn_pos, Byte_ascii .Nl_bry)); // add a "\n" tkn; note that adding a NewLine tkn doesn't // work, b/c Xoh_html_wtr has code to remove consecutive // \n; PAGE:en.w:Preferred_numbers DATE:2014-06-24 prv_nl_pos = bgn_pos; } } } prv_ws_bgn = 0; // MW: $t = substr( $t, 1 ); } else { if (bgn_pos - prv_nl_pos == 1 || line_is_ws) { // line is blank ("b" for blank) MW: if ( trim( $t ) === '' ) { if (para_stack != Para_stack_none) { // "b1"; stack has "<p>" or "</p><p>"; output "<br/>"; MW: if ( // $paragraphStack ) { Para_stack_end(cur_pos); Add_br(ctx, root, bgn_pos); // MW: $output .= $paragraphStack . '<br />'; para_stack = Para_stack_none; // MW: $paragraphStack = false; cur_mode = Mode_para; // MW: $this->mLastSection = 'p'; } else { // stack is empty if (cur_mode != Mode_para) { // "b2"; cur is '' or <pre> MW: if ( $this->mLastSection !== // 'p' ) { Prv_para_end(); // MW: $output .= $this->closeParagraph(); cur_mode = Mode_none; // MW: $this->mLastSection = ''; para_stack = Para_stack_bgn; // put <p> on stack MW: $paragraphStack = '<p>'; } else // "b3"; cur is p para_stack = Para_stack_mid; // put </p><p> on stack MW: $paragraphStack = '</p><p>'; } } else { // line has text ("t" for text); NOTE: tkn already added before \n, so must change // prv_para; EX: "a\n" -> this code is called for "\n" but "a" already processed if (para_stack != Para_stack_none) { // "t1" MW: if ( $paragraphStack ) { Para_stack_end(cur_pos); // MW: $output .= $paragraphStack; para_stack = Para_stack_none; // MW: $paragraphStack = false; cur_mode = Mode_para; // MW: $this->mLastSection = 'p'; } else if (cur_mode != Mode_para) { // "t2"; cur is '' or <pre> MW: elseif ( $this->mLastSection // !== 'p' ) { Prv_para_end(); Prv_para_bgn( Xop_para_tkn .Tid_para); // MW: $output .= $this->closeParagraph() . '<p>'; cur_mode = Mode_para; // MW: $this->mLastSection = 'p'; } else { } // "t3" } } } if (in_blockquote && prv_ws_bgn > 0) // handle blockquote separate; EX: <blockquote>\n\sa\n</blockquote>; note that "\s" // needs to be added literally; MW doesn't have this logic specifically, since it // assumes all characters go into $output, whereas XO, sets aside the "\s" in // "\n\s" separately prv_para.Space_bgn_(prv_ws_bgn); prv_ws_bgn = 0; // nl encountered and processed; always prv_ws_bgn set to 0, else ws from one line will // carry over to next // in_blockquote = false; block_is_bgn_xnde = block_is_end_xnde = false; // if ( $preCloseMatch && $this->mInPre ) // $this->mInPre = false; // prv_ws_bgn = false; Prv_para_new(ctx, root, bgn_pos, cur_pos); // add a prv_para placeholder if (para_stack == Para_stack_none) // "x1" MW: if ( $paragraphStack === false ) { if (prv_para != null) prv_para .Nl_bgn_y_(); // add nl; note that "$t" has already been processed; MW: $output .= $t . // "\n"; }