Repository: gatsbyjs/gatsby
File: packages/gatsby-remark-embed-snippet/src/index.js (JavaScript)

Code before:
  const extension = file.split(`.`).pop()

  return FILE_EXTENSION_TO_LANGUAGE_MAP.hasOwnProperty(extension)
    ? FILE_EXTENSION_TO_LANGUAGE_MAP[extension]
    : extension.toLowerCase()
}

module.exports = ({ markdownAST, markdownNode }, { directory } = {}) => {
  if (!directory) {
    directory = path.dirname(markdownNode.fileAbsolutePath)
  }

  if (!fs.existsSync(directory)) {
    throw Error(`Invalid directory specified "${directory}"`)
  }

  visit(markdownAST, `inlineCode`, node => {
    const { value } = node

    if (value.startsWith(`embed:`)) {
      const file = value.substr(6)
      let snippetPath = normalizePath(path.join(directory, file))

      // Embed specific lines numbers of a file
      let lines = []
      var sname = ``
      const rangePrefixIndex = snippetPath.indexOf(`#L`)
      if (rangePrefixIndex > -1) {
        const range = snippetPath.slice(rangePrefixIndex + 2)
        if (range.length === 1) {
          lines = [Number.parseInt(range, 10)]
        } else {
          lines = rangeParser.parse(range)
        }
        // Remove everything after the range prefix from file path
        snippetPath = snippetPath.slice(0, rangePrefixIndex)
      } else {
        // Check to see if there is a {snippet: "snippetName"} following the file path.
        // This syntax could support additional options in the future - for now, only
        // handle a string that contains a `snippet :` option.
        var optionIndex = snippetPath.indexOf(`{`)
        if (optionIndex > -1) {
          var optionStr = snippetPath.slice(optionIndex)
          snippetPath = snippetPath.slice(0, optionIndex)
          try {
            var optVal = JSON.parse(
              optionStr.replace(/snippet\s*:/, `"snippet":`)
            )
            if (
              typeof optVal != `undefined` &&
              typeof optVal.snippet != `undefined`

Review comment (suggestion):
Just small NIT :)

```suggestion
      let sname = ``
```

Code after:
  const extension = file.split(`.`).pop()

  return FILE_EXTENSION_TO_LANGUAGE_MAP.hasOwnProperty(extension)
    ? FILE_EXTENSION_TO_LANGUAGE_MAP[extension]
    : extension.toLowerCase()
}

module.exports = ({ markdownAST, markdownNode }, { directory } = {}) => {
  if (!directory) {
    directory = path.dirname(markdownNode.fileAbsolutePath)
  }

  if (!fs.existsSync(directory)) {
    throw Error(`Invalid directory specified "${directory}"`)
  }

  visit(markdownAST, `inlineCode`, node => {
    const { value } = node

    if (value.startsWith(`embed:`)) {
      const file = value.substr(6)
      let snippetPath = normalizePath(path.join(directory, file))

      // Embed specific lines numbers of a file
      let lines = []
      let sname = ``
      const rangePrefixIndex = snippetPath.indexOf(`#L`)
      if (rangePrefixIndex > -1) {
        const range = snippetPath.slice(rangePrefixIndex + 2)
        if (range.length === 1) {
          lines = [Number.parseInt(range, 10)]
        } else {
          lines = rangeParser.parse(range)
        }
        // Remove everything after the range prefix from file path
        snippetPath = snippetPath.slice(0, rangePrefixIndex)
      } else {
        // Check to see if there is a {snippet: "snippetName"} following the file path.
        // This syntax could support additional options in the future - for now, only
        // handle a string that contains a `snippet :` option.
        const optionIndex = snippetPath.indexOf(`{`)
        if (optionIndex > -1) {
          const optionStr = snippetPath.slice(optionIndex)
          snippetPath = snippetPath.slice(0, optionIndex)
          try {
            const optVal = JSON.parse(
              optionStr.replace(/snippet\s*:/, `"snippet":`)
            )
            if (
              typeof optVal != `undefined` &&
              typeof optVal.snippet != `undefined`