Skip to content

gatsby-remark-prismjs adding newlines to inline code blocks #4802

@adamyonk

Description

@adamyonk

Description

I'm seeing a newline added at the end of inline code blocks, but only if there is a inlineCodeMarker present.

image
image

Steps to reproduce

Here's the markdown in question:

When Jekyll picks up my built bundle to compile it into `/_site`, it will now
have the triple-dashes prepended to the file. I use the `style-loader` with
Webpack so that I can `javascript±require` styles in my JavaScript and have
them written to the document `<head>`. So now I'll be able to use Liquid tags
for things like this:

Expected result

No newline added after inline code with inlineCodeMarker.

Actual result

Newline added after inline code.

Environment

  • Gatsby version (npm list gatsby): 1.9.243
  • gatsby-cli version (gatsby --version): 1.9.243
  • Node.js version: 8.9.4
  • Operating System: macOS 10.13.3

File contents (if changed):

gatsby-config.js:

module.exports = {
  siteMetadata: {
    title: "Adam Jahnke ☕️🏍 (adamyonk)",
    description: "",
    siteUrl: "https://adamyonk.com",
    author: "Adam Jahnke",
  },
  plugins: [
    { resolve: "gatsby-plugin-react-next" },
    { resolve: "gatsby-plugin-react-helmet" },
    { resolve: "gatsby-plugin-styled-jsx" },
    {
      resolve: "gatsby-plugin-feed-generator",
      feedQuery: `
        {
          allMarkdownRemark(
            filter: { frontmatter: { templateKey: { eq: "post" } } }
            sort: { order: DESC, fields: [frontmatter___date] }
          ) {
            edges {
              node {
                html
                id
                frontmatter {
                  date
                  path
                  title
                }
              }
            }
          }
        }
      `,
    },
    {
      resolve: "gatsby-source-filesystem",
      options: {
        path: `${__dirname}/src/pages`,
        name: "pages",
      },
    },
    {
      resolve: "gatsby-transformer-remark",
      options: {
        plugins: [
          {
            resolve: "gatsby-remark-prismjs",
            options: {
              inlineCodeMarker: "±",
            },
          },
          {
            resolve: "gatsby-remark-images",
            options: {
              maxWidth: 800,
              linkImagesToOriginal: true,
            },
          },
        ],
      },
    },
  ],
}

package.json:

{
  "name": "adamyonk.com",
  "description": "",
  "version": "1.0.0",
  "author": "Adam Jahnke",
  "dependencies": {
    "date-fns": "^1.29.0",
    "gatsby": "^1.9.243",
    "gatsby-link": "^1.6.40",
    "gatsby-plugin-feed-generator": "^1.0.5",
    "gatsby-plugin-react-helmet": "^1.0.8",
    "gatsby-plugin-react-next": "^1.0.11",
    "gatsby-plugin-styled-jsx": "^2.0.6",
    "gatsby-remark-images": "^1.5.60",
    "gatsby-remark-prismjs": "^1.2.21",
    "gatsby-source-filesystem": "^1.5.27",
    "gatsby-transformer-remark": "^1.7.39",
    "prettier": "^1.11.1",
    "styled-jsx": "^2.2.6"
  },
  "private": true,
  "main": "n/a",
  "scripts": {
    "build": "gatsby build",
    "start": "gatsby develop",
    "format": "prettier './*.{js,json}' '.{babel,prettier}rc' 'src/**/*.{js,json,md}' --write ",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "devDependencies": {}
}

gatsby-node.js:

const path = require("path")

exports.createPages = ({ boundActionCreators, graphql }) => {
  const { createPage } = boundActionCreators

  return graphql(`
    {
      pages: allMarkdownRemark(
        sort: { order: DESC, fields: [frontmatter___date] }
        limit: 1000
      ) {
        edges {
          node {
            excerpt(pruneLength: 400)
            html
            id
            frontmatter {
              templateKey
              path
              date
              title
            }
          }
        }
      }
      posts: allMarkdownRemark(
        filter: { frontmatter: { templateKey: { eq: "post" } } }
        limit: 1000
      ) {
        edges {
          node {
            frontmatter {
              tags
            }
          }
        }
      }
    }
  `).then(result => {
    if (result.errors) {
      return Promise.reject(result.errors)
    }
    result.data.posts.edges
      .reduce((a, { node: { frontmatter: { tags } } }) => {
        for (const tag of tags) {
          a.add(tag)
        }
        return a
      }, new Set())
      .forEach(tag => {
        createPage({
          path: `/tags/${tag}`,
          component: path.resolve(`src/templates/tag.js`),
          context: { tag }, // additional data can be passed via context
        })
      })
    result.data.pages.edges.forEach(({ node }) => {
      createPage({
        path: node.frontmatter.path,
        component: path.resolve(
          `src/templates/${String(node.frontmatter.templateKey)}.js`
        ),
        context: {}, // additional data can be passed via context
      })
    })
  })
}

gatsby-browser.js:
gatsby-ssr.js:

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions