當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。