Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法让PrismJS使用GatsbyJS处理我的代码_Javascript_Reactjs_Gatsby_Prismjs - Fatal编程技术网

Javascript 无法让PrismJS使用GatsbyJS处理我的代码

Javascript 无法让PrismJS使用GatsbyJS处理我的代码,javascript,reactjs,gatsby,prismjs,Javascript,Reactjs,Gatsby,Prismjs,我试图将GraphQL/GraphCMS查询的输出(包在块中的元素)转换为带有PRISMJ的高亮显示的代码块。为了获得当前的设置,我按照教程进行了操作,并尝试使用html输出,而不是降价 以下是我用来完成此任务的代码: import React from "react"; import { useEffect } from "react"; import { graphql, Link } from 'gatsby'; import Layout from

我试图将GraphQL/GraphCMS查询的输出(包在
块中的元素)转换为带有PRISMJ的高亮显示的代码块。为了获得当前的设置,我按照教程进行了操作,并尝试使用html输出,而不是降价

以下是我用来完成此任务的代码:

import React from "react";
import { useEffect } from "react";
import { graphql, Link } from 'gatsby';
import Layout from "../components/layout";
import SEO from "../components/seo";

//import the Prism package
import Prism from "prismjs";**strong text**

//Import showdown Markdowm Parser
let showdown  = require('showdown');

let htmlOutput = '';
let markdownOutput = '';

const PostPage = ({ data }) => {
  const { post } = data.gcms;

  htmlOutput = post.content.html;

  //Convert Markdown Output to HTML
  let converter = new showdown.Converter();
  let markdownOutput = converter.makeHtml(post.content.markdown);

  //Define array for SEO Keywords - Set with basic keyword setup
  let arr = [];

  useEffect(() => {
    // call the highlight() function to style our code blocks
    markdownOutput = Prism.highlight(markdownOutput, Prism.languages.javascript, 'javascript');
    htmlOutput = Prism.highlight(htmlOutput, Prism.languages.javascript, 'javascript');
  });

  return (
  <Layout>
    <SEO
      title={post.title}
      description={post.excerpt}
      image={post.coverImage.url}
        {
          ...post.tags.map((tag) => 
            arr.push(tag)
          )
        }
        keywords = {arr}
        title={post.title}
      />
    <section className="w-full text-gray-700 body-font">
      <div className="container flex flex-col justify-center px-5 pb-24 mx-auto">
      <h1 className="flex justify-center mb-12 text-4xl font-semibold text-center text-black">{post.title}</h1>
        <div className="flex flex-col justify-center">
          <div className="h-64 overflow-hidden rounded-lg border-1 border-gray-light">
            <img alt="content" className="object-cover object-center w-full h-full" src={post.coverImage.url}></img>
          </div>
          <div className="flex flex-row justify-between w-full mt-4">
            <span className="flex flex-col pl-8 mt-6">
              <h3 className="text-2xl">{post.author.name}</h3>
              <h4 className="text-black-lighter">Published: {post.date}</h4>
            </span>
            <span className="pr-8 mt-6">
            { 
              post.tags.map((tag) =>
                <span key={tag} className="inline-block px-3 py-1 mb-2 mr-2 text-xs font-medium tracking-widest capitalize border-2 border-dashed rounded border-black-lighter text-blue bg-blue-indigo">{tag}</span>
              )
            }
            </span>
          </div>
          <div id="blogPost" className="flex flex-col mt-4 sm:flex-row">
            {/* <div>Notication Section Here. </div> */}
            {/* {Post Content} */}
            <div className="pt-4 mt-4 text-center border-t border-gray-300 sm:w-full sm:pl-8 sm:py-8 sm:border-t-0 sm:mt-0 sm:text-left">
              <div dangerouslySetInnerHTML={{ __html: htmlOutput }} className="mb-4 text-lg leading-normal sm:pr-8"></div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </Layout>
)};

export const pageQuery = graphql`
  query postPageQuery($id: ID!) {
    gcms {
      post(where: { id: $id }) {
        id
        title
        slug
        excerpt
        coverImage {
          url
        }
        tags
        author {
          name
          biography
          picture {
            coverImagePost {
              coverImage {
                url
              }
            }
          }
        }
        content {
          html
          markdown
          text
        }
        date
        seo {
          title
          description
          keywords
        }
      }
    }
  }
`;

export default PostPage;
从“React”导入React;
从“react”导入{useffect};
从“盖茨比”导入{graphql,Link};
从“./组件/布局”导入布局;
从“./组件/SEO”导入SEO;
//导入Prism包
从“prismjs”导入Prism**强文本**
//导入决战Markdowm解析器
让决战=要求(‘决战’);
让htmlOutput='';
让markdownOutput='';
const PostPage=({data})=>{
const{post}=data.gcms;
htmlOutput=post.content.html;
//将降价输出转换为HTML
让converter=new shodown.converter();
让markdownOutput=converter.makeHtml(post.content.markdown);
//为SEO关键字定义数组-使用基本关键字设置设置
设arr=[];
useffect(()=>{
//调用highlight()函数来设置代码块的样式
markdownOutput=Prism.highlight(markdownOutput,Prism.languages.javascript,'javascript');
htmlOutput=Prism.highlight(htmlOutput,Prism.languages.javascript,'javascript');
});
返回(
arr.push(标签)
)
}
关键词={arr}
title={post.title}
/>
{post.title}
{post.author.name}
已发布:{post.date}
{ 
post.tags.map((标记)=>
{tag}
)
}
{/*此处为通知部分。*/}
{/*{Post Content}*/}
)};
export const pageQuery=graphql`
查询postPageQuery($id:id!){
gcms{
post(其中:{id:$id}){
身份证件
标题
鼻涕虫
节选
封面图片{
网址
}
标签
作者{
名称
传记
图画{
封面图片{
封面图片{
网址
}
}
}
}
内容{
html
降价
文本
}
日期
搜索引擎优化{
标题
描述
关键词
}
}
}
}
`;
导出默认延迟;

当前结果是什么?你能举一个输入的例子吗?重复:当前结果是什么?你能举一个例子说明输入的内容是什么吗