当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript parse-entities.default函数代码示例

本文整理汇总了TypeScript中parse-entities.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: entityPrefixLength

/**
 * Returns the length of HTML entity that is a prefix of
 * the given string (excluding the '&'), 0 if it
 * does not start with an entity.
 *
 * @example
 *   entityPrefixLength('&copycat') // 4
 *   entityPrefixLength('&foo &amp &bar') // 0
 *
 * @param {string} value - Input string.
 * @return {number} - Length of an entity.
 */
export default function entityPrefixLength (value: string): number {
  /* istanbul ignore if - Currently also tested for at
   * implemention, but we keep it here because that’s
   * proper. */
  if (value.charAt(0) !== '&') {
    return 0
  }

  const prefix = value.split('&', 2).join('&')

  return prefix.length - decode(prefix).length
}
开发者ID:mosjs,项目名称:mos-core,代码行数:24,代码来源:entity-prefix-length.ts

示例2: decode

 const decoder: Decoder = Object.assign(function (value: string, position: Location, handler: Function): void {
   decode(value, {
     position: normalize(position),
     warning: handleWarning,
     text: handler,
     reference: handler,
     textContext: context,
     referenceContext: context,
   })
 }, {
开发者ID:mosjs,项目名称:mos-core,代码行数:10,代码来源:index.ts

示例3: function

const tokenizeURL: Tokenizer = function (parser, value, silent) {
  if (!parser.options.gfm) {
    return
  }

  const match = value.match(beginsWithProtocol)

  if (!match) {
    return
  }

  let subvalue = match[0]

  let index = subvalue.length
  const length = value.length
  let queue = ''
  let parenCount = 0

  while (index < length) {
    const character = value.charAt(index)

    if (isWhiteSpace(character) || character === '<') {
      break
    }

    if (~'.,:;"\')]'.indexOf(character)) {
      const nextCharacter = value.charAt(index + 1)

      if (
        !nextCharacter ||
        isWhiteSpace(nextCharacter)
      ) {
        break
      }
    }

    if (
      character === '(' ||
      character === '['
    ) {
      parenCount++
    }

    if (
      character === ')' ||
      character === ']'
    ) {
      parenCount--

      if (parenCount < 0) {
        break
      }
    }

    queue += character
    index++
  }

  if (!queue) {
    return
  }

  subvalue += queue
  let content = subvalue

  if (subvalue.indexOf(MAILTO_PROTOCOL) === 0) {
    const position = queue.indexOf('@')

    if (position === -1 || position === length - 1) {
      return
    }

    content = content.substr(MAILTO_PROTOCOL.length)
  }

  /* istanbul ignore if - never used (yet) */
  if (silent) {
    return true
  }

  const now = parser.eat.now()

  return parser.eat(subvalue)(
    renderLink(parser, decode(subvalue), content, null, now)
  )
}
开发者ID:mosjs,项目名称:mos-core,代码行数:86,代码来源:url.ts

示例4: function

const tokenizeURL: Tokenizer = function (parser, value, silent) {
  if (!parser.options.gfm) {
    return false
  }

  const scanner = createScanner(value)
  let subvalue = scanner.next(beginsWithProtocol)

  if (!subvalue) {
    return false
  }

  let queue = ''
  let parenCount = 0

  while (!scanner.eos()) {
    const character = scanner.next()

    if (isWhiteSpace(character) || character === '<') {
      break
    }

    if (~'.,:;"\')]'.indexOf(character)) {
      const nextCharacter = scanner.peek()

      if (
        !nextCharacter ||
        isWhiteSpace(nextCharacter)
      ) {
        break
      }
    }

    if (
      character === '(' ||
      character === '['
    ) {
      parenCount++
    }

    if (
      character === ')' ||
      character === ']'
    ) {
      parenCount--

      if (parenCount < 0) {
        break
      }
    }

    queue += character
  }

  if (!queue) {
    return false
  }

  subvalue += queue
  let content = subvalue

  if (subvalue.indexOf(MAILTO_PROTOCOL) === 0) {
    const position = queue.indexOf('@')

    if (position === -1 || position === value.length - 1) {
      return false
    }

    content = content.substr(MAILTO_PROTOCOL.length)
  }

  /* istanbul ignore if - never used (yet) */
  if (silent) {
    return true
  }

  const now = parser.eat.now()

  return parser.eat(subvalue)(
    renderLink(parser, decode(subvalue), content, null, now)
  )
}
开发者ID:mosjs,项目名称:mos,代码行数:82,代码来源:url.ts

示例5: renderLink

const tokenizeAutoLink: Tokenizer = function (parser, value, silent) {
  const scanner = createScanner(value)

  if (scanner.next() !== '<') {
    return false
  }

  let subvalue = ''
  let queue = ''
  let hasAtCharacter = false
  let link = ''

  subvalue = '<'

  while (!scanner.eos()) {
    let character = scanner.next()

    if (
      character === ' ' ||
      character === '>' ||
      character === '@' ||
      (character === ':' && scanner.peek() === '/')
    ) {
      scanner.moveIndex(-1)
      break
    }

    queue += character
  }

  if (!queue) {
    return false
  }

  link += queue
  queue = ''

  let character = scanner.next()
  link += character

  if (character === '@') {
    hasAtCharacter = true
  } else {
    if (
      character !== ':' ||
      scanner.peek() !== '/'
    ) {
      return false
    }

    link += '/'
    scanner.moveIndex(1)
  }

  while (!scanner.eos()) {
    character = scanner.next()

    if (character === ' ' || character === '>') {
      scanner.moveIndex(-1)
      break
    }

    queue += character
  }

  character = scanner.next()

  if (!queue || character !== '>') {
    return false
  }

  /* istanbul ignore if - never used (yet) */
  if (silent) {
    return true
  }

  link += queue
  let content = link
  subvalue += link + character
  const now = parser.eat.now()
  now.column++
  now.offset++

  if (hasAtCharacter) {
    if (
      link.substr(0, MAILTO_PROTOCOL.length).toLowerCase() !== MAILTO_PROTOCOL
    ) {
      link = MAILTO_PROTOCOL + link
    } else {
      content = content.substr(MAILTO_PROTOCOL.length)
      now.column += MAILTO_PROTOCOL.length
      now.offset += MAILTO_PROTOCOL.length
    }
  }

  parser.context.inAutoLink = true
  const eater = parser.eat(subvalue)
  return renderLink(parser, decode(link), content, null, now)
    .then(node => {
      parser.context.inAutoLink = false
//.........这里部分代码省略.........
开发者ID:mosjs,项目名称:mos,代码行数:101,代码来源:auto-link.ts

示例6: renderLink

const tokenizeAutoLink: Tokenizer = function (parser, value, silent) {
  if (value.charAt(0) !== '<') {
    return
  }

  let subvalue = ''
  const length = value.length
  let index = 0
  let queue = ''
  let hasAtCharacter = false
  let link = ''

  index++
  subvalue = '<'

  while (index < length) {
    var character = value.charAt(index)

    if (
      character === ' ' ||
      character === '>' ||
      character === '@' ||
      (character === ':' && value.charAt(index + 1) === '/')
    ) {
      break
    }

    queue += character
    index++
  }

  if (!queue) {
    return
  }

  link += queue
  queue = ''

  character = value.charAt(index)
  link += character
  index++

  if (character === '@') {
    hasAtCharacter = true
  } else {
    if (
      character !== ':' ||
      value.charAt(index + 1) !== '/'
    ) {
      return
    }

    link += '/'
    index++
  }

  while (index < length) {
    character = value.charAt(index)

    if (character === ' ' || character === '>') {
      break
    }

    queue += character
    index++
  }

  character = value.charAt(index)

  if (!queue || character !== '>') {
    return
  }

  /* istanbul ignore if - never used (yet) */
  if (silent) {
    return true
  }

  link += queue
  let content = link
  subvalue += link + character
  const now = parser.eat.now()
  now.column++
  now.offset++

  if (hasAtCharacter) {
    if (
      link.substr(0, MAILTO_PROTOCOL.length).toLowerCase() !==
      MAILTO_PROTOCOL
    ) {
      link = MAILTO_PROTOCOL + link
    } else {
      content = content.substr(MAILTO_PROTOCOL.length)
      now.column += MAILTO_PROTOCOL.length
      now.offset += MAILTO_PROTOCOL.length
    }
  }

  const exitAutoLink = parser.state.enterAutoLink()
  const eater = parser.eat(subvalue)
//.........这里部分代码省略.........
开发者ID:mosjs,项目名称:mos-core,代码行数:101,代码来源:auto-link.ts


注:本文中的parse-entities.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。