Exemple #1
0
StringRef getLiteralContent(MarkupContext &MC, LineList &LL, cmark_node *Node) {
  // Literal content nodes never have start/end column line information.
  // It is a floating piece of text that inherits location information from
  // its parent.
  auto Literal = cmark_node_get_literal(Node);
  assert(Literal != nullptr);
  return MC.allocateCopy(StringRef(Literal));
}
Exemple #2
0
StringRef getLiteralContent(MarkupContext &MC, LineList &LL, cmark_node *Node) {
  // Literal content nodes never have start/end column line information.
  // It is a floating piece of text that inherits location information from
  // its parent.
  auto Literal = cmark_node_get_literal(Node);
  assert(Literal != nullptr);
  size_t Length = 0;
  switch (cmark_node_get_type(Node)) {
  case CMARK_NODE_CODE_BLOCK:
    Length = Node->as.code.literal.len;
    break;
  default:
    Length = Node->as.literal.len;
  }
  return MC.allocateCopy(StringRef(Literal, Length));
}
Exemple #3
0
ParseResult<CodeBlock> parseCodeBlock(MarkupContext &MC, LineList &LL,
                                      ParseState State) {
  assert(cmark_node_get_type(State.Node) == CMARK_NODE_CODE_BLOCK
      && State.Event == CMARK_EVENT_ENTER);

  StringRef Language("swift");

  if (auto FenceInfo = cmark_node_get_fence_info(State.Node)) {
    StringRef FenceInfoStr(FenceInfo);
    if (!FenceInfoStr.empty())
      Language = MC.allocateCopy(FenceInfoStr);
  }
  return { CodeBlock::create(MC, getLiteralContent(MC, LL, State.Node),
                             Language),
           State.next() };
}