Block parser for UU5.RichText.Block .

The rich text block is using following signature:

{richtext}
...richtext content...

{/richtext}

@param state
@param startLine
@param endLine
@param silent
@returns {boolean}
9763
function richtext(state, startLine, endLine, silent, opts) {
  let pos = state.bMarks[startLine] + state.tShift[startLine],
    max = state.eMarks[startLine],
    contentEndLine;

  if (pos >= max) {
    return false;
  }

  let line = state.getLines(startLine, startLine + 1, 0, false);

  if (!line.startsWith(RICHTEXT_OPEN_MARKER)) {
    return false;
  }

  if (silent) {
    return true;
  }

  let nextLine = startLine + 1;
  let content = "";

  for (; nextLine < endLine; nextLine++) {
    let line = state.getLines(nextLine, nextLine + 1, 0, false);

    if (line.trim() === RICHTEXT_CLOSE_MARKER) {
      contentEndLine = nextLine - 1;
      break;
    }
    content += line + "\n";
  }

  state.line = contentEndLine + 2;

  // convert md subcontent to uu5string
  let uu5content = opts.markdownToUu5.render(content, state.env);

  state.tokens.push({
    type: "UU5.RichText.Block",
    uu5string: uu5content
  });
  return true;
}
708473
JCBlock block(int pos, long flags) {
        accept(LBRACE);
        List<JCStatement> stats = blockStatements();
        JCBlock t = F.at(pos).Block(flags, stats);
        while (token.kind == CASE || token.kind == DEFAULT) {
            syntaxError("orphaned", token.kind);
            switchBlockStatementGroups();
        }
        // the Block node has a field "endpos" for first char of last token, which is
        // usually but not necessarily the last char of the last token.
        t.endpos = token.pos;
        accept(RBRACE);
        return toP(t);
    }
980331
def highlight_block(self, text):
        """"""
        text = to_text_string(text)
        previous_state = tbh.get_state(self.currentBlock().previous())
        
        if previous_state == self.COMMENT:
            self.setFormat(0, len(text), self.formats["comment"])
        else:
            previous_state = self.NORMAL
            self.setFormat(0, len(text), self.formats["normal"])
        
        tbh.set_state(self.currentBlock(), previous_state)
        match = self.PROG.search(text)        

        match_count = 0
        n_characters = len(text)
        # There should never be more matches than characters in the text.
        while match and match_count < n_characters:
            match_dict = match.groupdict()
            for key, value in list(match_dict.items()):
                if value:
                    start, end = match.span(key)
                    if previous_state == self.COMMENT:
                        if key == "multiline_comment_end":
                            tbh.set_state(self.currentBlock(), self.NORMAL)
                            self.setFormat(end, len(text),
                                           self.formats["normal"])
                        else:
                            tbh.set_state(self.currentBlock(), self.COMMENT)
                            self.setFormat(0, len(text),
                                           self.formats["comment"])
                    else:
                        if key == "multiline_comment_start":
                            tbh.set_state(self.currentBlock(), self.COMMENT)
                            self.setFormat(start, len(text),
                                           self.formats["comment"])
                        else:
                            tbh.set_state(self.currentBlock(), self.NORMAL)
                            try:
                                self.setFormat(start, end-start,
                                               self.formats[key])
                            except KeyError:
                                # happens with unmatched end-of-comment;
                                # see issue 1462
                                pass
            
            match = self.PROG.search(text, match.end())
            match_count += 1
        
        self.highlight_spaces(text)
180319
function block(toks, i, n, handler) {
    ++i; //  skip over '{'
    if (handler['startBlock']) { handler['startBlock'](); }
    while (i < n) {
      var ch = toks[i].charAt(0);
      if (ch == '}') {
        ++i;
        break;
      }
      if (ch === ' ' || ch === ';') {
        i = i+1;
      } else if (ch === '@') {
        i = atrule(toks, i, n, handler, false);
      } else if (ch === '{') {
        i = block(toks, i, n, handler);
      } else {
        // Instead of using (any* block) to subsume ruleset we allow either
        // blocks or rulesets with a non-blank selector.
        // This is more restrictive but does not require atrule specific
        // parse tree fixup to realize that the contents of the block in
        //    @media print { ... }
        // is a ruleset.  We just don't care about any block carrying at-rules
        // whose body content is not ruleset content.
        i = ruleset(toks, i, n, handler);
      }
    }
    if (handler['endBlock']) { handler['endBlock'](); }
    return i;
  }
569001
function(block) {
  if (block.last_line_blank) {
    return true;
  }
  if ((block.t == 'List' || block.t == 'ListItem') && block.children.length > 0) {
    return endsWithBlankLine(block.children[block.children.length - 1]);
  } else {
    return false;
  }
}
1027262
def complete(self, text, state):
        
        if self.use_main_ns:
            self.namespace = __main__.__dict__

        if not text.strip():
            if state == 0:
                if _readline_available:
                    readline.insert_text('\t')
                    readline.redisplay()
                    return ''
                else:
                    return '\t'
            else:
                return None

        if state == 0:
            if "." in text:
                self.matches = self.attr_matches(text)
            else:
                self.matches = self.global_matches(text)
        try:
            return self.matches[state]
        except IndexError:
            return None
384375
def highlightBlock(self, text):
        
        text = nativestring(text)
        for pattern, format in self.patterns():
            for result in re.finditer(pattern, text):
                grps = result.groups()
                if grps:
                    for i in range(len(grps)):
                        start, end = result.span(i+1)
                        self.setFormat(start, end - start, format)
                else:
                    self.setFormat(result.start(),
                                   result.end() - result.start(),
                                   format)
        
        self.setCurrentBlockState(0)
        if self.previousBlockState() == 1:
            return
        
        for form, open, close in self._multiline:
            open = QtCore.QRegExp(open)
            close = QtCore.QRegExp(close)
            
            start = open.indexIn(text)
            processed = False
            
            while start >= 0:
                processed = True
                end = close.indexIn(text, start)

                if end == -1:
                    self.setCurrentBlockState(1)
                    length = len(text) - start
                else:
                    length = end - start + close.matchedLength()

                self.setFormat(start, length, form)
                start = open.indexIn(text, start + length)
            
            if processed:
                break
413622
function prefixBlock(prefix, block, skipEmpty) {
    var lines = block.split('\n');
    for (var i =0; i<lines.length; i++) {
      // Do not prefix empty lines
      if (lines[i].length === 0 && skipEmpty === true)
        continue;
      else
        lines[i] = prefix + lines[i];
    }
    return lines.join('\n');
  }
1074795
function()
		{
			var startContainer = this.startContainer,
				startOffset = this.startOffset;

			// If the starting node is a text node, and non-empty before the offset,
			// then we're surely not at the start of block.
			if ( startOffset && startContainer.type == CKEDITOR.NODE_TEXT )
			{
				var textBefore = CKEDITOR.tools.ltrim( startContainer.substring( 0, startOffset ) );
				if ( textBefore.length )
					return false;
			}

			// Antecipate the trim() call here, so the walker will not make
			// changes to the DOM, which would not get reflected into this
			// range otherwise.
			this.trim();

			// We need to grab the block element holding the start boundary, so
			// let's use an element path for it.
			var path = new CKEDITOR.dom.elementPath( this.startContainer );

			// Creates a range starting at the block start until the range start.
			var walkerRange = this.clone();
			walkerRange.collapse( true );
			walkerRange.setStartAt( path.block || path.blockLimit, CKEDITOR.POSITION_AFTER_START );

			var walker = new CKEDITOR.dom.walker( walkerRange );
			walker.evaluator = getCheckStartEndBlockEvalFunction( true );

			return walker.checkBackward();
		}
793496
CssFormatter startBlock( String[] selectors ) {
        final List<CssOutput> results = state.results;
        if( blockDeep == 0 ) {
            output = null;
            CssOutput nextOutput = null;
            if( results.size() > 0 && !"@font-face".equals( selectors[0] ) ) {
                CssOutput cssOutput = results.get( results.size() - 1 );
                if( Arrays.equals( selectors, cssOutput.getSelectors() ) ) {
                    nextOutput = cssOutput;
                }
            }
            CssFormatter block;
            if( nextOutput == null ) {
                block = copy( null );
                if( selectors[0].startsWith( "@media" ) ) {
                    block.lessExtends = new LessExtendMap( state.lessExtends );
                    nextOutput = new CssMediaOutput( selectors, block.output, state.isReference, block.lessExtends );
                } else {
                    nextOutput = new CssRuleOutput( selectors, block.output, state.isReference );
                }
                results.add( nextOutput );
            } else {
                block = copy( nextOutput.getOutput() );
            }
            block.currentOutput = nextOutput;
            block.incInsets();
            block.blockDeep++;
            return block;
        } else {
            if( selectors[0].startsWith( "@media" ) ) {
                CssFormatter block = copy( null );
                block.lessExtends = new LessExtendMap( state.lessExtends );
                String[] sel = new String[]{ this.currentOutput.getSelectors()[0] + " and " + selectors[0].substring( 6 ).trim() };
                block.currentOutput = new CssMediaOutput( sel, block.output, state.isReference, block.lessExtends );
                results.add( block.currentOutput );
                block.insets.setLength( 2 );
                block.blockDeep = 1;
                return block;
            } else {
                if( blockDeep == 1 && this.currentOutput.getClass() == CssMediaOutput.class ) {
                    CssFormatter block = copy( null );
                    block.incInsets();
                    block.currentOutput = this.currentOutput;
                    ((CssMediaOutput)this.currentOutput).startBlock( selectors, block.output );
                    block.blockDeep++;
                    return block;
                } else {
                    blockDeep++;
                    startBlockImpl( selectors );
                    return this;
                }
            }
        }
    }
395712
public static IBlockState ParseBlockType( String s )
    {
        if( s == null )
            return null; 
        Block block = (Block)Block.REGISTRY.getObject(new ResourceLocation( s ));
        if( block instanceof BlockAir && !s.equals("air") ) // Minecraft returns BlockAir when it doesn't recognise the string
            return null; // unrecognised string
        return block.getDefaultState();
    }
1015948
function onComment(block, text, start, stop, startLoc, endLoc) {
      var match;
      commentsByEndLine[endLoc.line] = {
        text: text,
        block: block
      };
      match = text.match(/@module (\w+)/);
      if (match) {
        moduleName = match[1];
        modules.push({
          name: moduleName,
          comment: '/*' + text + '*/\n'
        });
      }
      // Both @module and @namespace may be defined in the same comment block.
      match = text.match(/@(namespace|module) \w+/g);
      if (match) {
        if (text.match(/@method/)) {
          // Don't allow temporary namespace renamings
          // in method block.
          return;
        }
        var namespace = match[match.length - 1].match(/@(namespace|module) (\w+)/)[2];
        namespaceBoundary(namespace, endLoc.line);
      }
    }
1202115
function isCaretAtStartOrEndOfBlock(start) {
          var walker, node, name;

          // Caret is in the middle of a text node like "a|b"
          if (container.nodeType == 3 && (start ? offset > 0 : offset < container.nodeValue.length)) {
            return false;
          }

          // If after the last element in block node edge case for #5091
          if (container.parentNode == parentBlock && isAfterLastNodeInContainer && !start) {
            return true;
          }

          // If the caret if before the first element in parentBlock
          if (start && container.nodeType == 1 && container == parentBlock.firstChild) {
            return true;
          }

          // Caret can be before/after a table
          if (container.nodeName === "TABLE" || (container.previousSibling && container.previousSibling.nodeName == "TABLE")) {
            return (isAfterLastNodeInContainer && !start) || (!isAfterLastNodeInContainer && start);
          }

          // Walk the DOM and look for text nodes or non empty elements
          walker = new TreeWalker(container, parentBlock);

          // If caret is in beginning or end of a text block then jump to the next/previous node
          if (container.nodeType == 3) {
            if (start && offset === 0) {
              walker.prev();
            } else if (!start && offset == container.nodeValue.length) {
              walker.next();
            }
          }

          while ((node = walker.current())) {
            if (node.nodeType === 1) {
              // Ignore bogus elements
              if (!node.getAttribute('data-mce-bogus')) {
                // Keep empty elements like <img /> <input /> but not trailing br:s like <p>text|<br></p>
                name = node.nodeName.toLowerCase();
                if (nonEmptyElementsMap[name] && name !== 'br') {
                  return false;
                }
              }
            } else if (node.nodeType === 3 && !/^[ \t\r\n]*$/.test(node.nodeValue)) {
              return false;
            }

            if (start) {
              walker.prev();
            } else {
              walker.next();
            }
          }

          return true;
        }
366976
private void parseRule( Rule rule ) {
        ruleStack.add( rule );
        for( ;; ) {
            int ch = reader.nextBlockMarker();
            switch( ch ) {
                case -1:
                    throw createException( "Unexpected end of Less data" );
                case ';':
                    parseSemicolon( rule );
                    break;
                case '{':
                    parseBlock( rule );
                    break;
                case '}':
                    parseSemicolon( rule );
                    ruleStack.removeLast();
                    return;
                default:
                    throw createException( "Unrecognized input: '" + reader.getLookAhead() + "'" );
            }
        }

    }
875662
private int parseListItem (int start) {
        start = skipSpacesToNewline(start, wikiLength); // skip spaces
        int end=parseItem(start, null, ContextType.LIST_ITEM);
        if ((listLevels[listLevel]=='>' || listLevels[listLevel]==':') &&
            wikiText.substring(start, end).trim().length()==0) { // empty line within blockquote/div
            if (!blockquoteBR) {
                sb.append("<br/><br/>");
                blockquoteBR=true;
            }
        }
        else {
            blockquoteBR=false;
        }
        return end;
    }
94459
Rule XcomTextblock() {
		return Sequence(String("begintext"), OptionalS(TextblockParam()), Eol(),
				ZeroOrMoreS(SequenceS(OptionalS(String("%%")), TexText(), Eol())),
				String("%%endtext")
				).label(XcomTextblock);
	}
1225682
private static int getBlockLength(String text, int offset)
   {
      int startIndex = offset;
      boolean finished = false;
      char c;

      while (finished == false)
      {
         c = text.charAt(offset);
         switch (c)
         {
            case '\r':
            case '\n':
            case '}':
            {
               finished = true;
               break;
            }

            default:
            {
               ++offset;
               break;
            }
         }
      }

      int length = offset - startIndex;

      return (length);
   }