Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Style after packaging #45

Open
byAaronLuo opened this issue Jul 10, 2023 · 9 comments
Open

Change Style after packaging #45

byAaronLuo opened this issue Jul 10, 2023 · 9 comments

Comments

@byAaronLuo
Copy link

I have discovered a new issue based on issue # 44. When I customize an hljs object and the highlighted code I need is HTTP RESPONSE, the highlighted code in the production and development environments is different, as shown in the following two images. The first image is the development environment, which only highlights the HTML; The second image shows the production environment, which only highlights the HTTP response header. Why are the highlighted codes in the production and development environments different? How should I solve the problem of production environments being out of sync with development environments

image image

ps:
Packaging tool: vue/cli 5.0.8
Dependency version: @highlightjs/vue-plugin:^2.1.2
main.js

import 'highlight.js/styles/atom-one-dark.css'
import 'highlight.js/lib/common'
import hljs from 'highlight.js/lib/core'
import hljsVuePlugin from '@highlightjs/vue-plugin'
import javascript from 'highlight.js/lib/languages/javascript'
hljs.registerLanguage('javascript', javascript)
app.use(hljsVuePlugin)

SFC:

<template>
  <div>
    <highlightjs autodetect :code="code"></highlightjs>
  </div>
</template>
@byAaronLuo
Copy link
Author

Maybe I should ask if this is a bug? Is there something wrong with my packaging with vue-cli? So far I've only found this problem with the http response package

@joshgoebel
Copy link
Member

joshgoebel commented Jul 10, 2023

Sounds like some sort of build problem... maybe? The highlighting shouldn't be different unless something at the JS level was different between your two environments. Maybe looking closely at your developer tools could help?

Look at the rendered code (in your browsers dev tools)... is the auto-detect somehow different? (css lang class)

@wb-wenbei
Copy link

wb-wenbei commented Jul 11, 2023

import 'highlight.js/lib/common' is ignored in package.
The second image hightlight the code as javascript.
You should register the HTML language to highlight the code.

@byAaronLuo
Copy link
Author

I found the problem, in the development tool the attributes of the code tag are not loaded with the corresponding CSS, e.g., the class of the highlighted http response in the development environment is hljs xml, in the production environment it is hljs javascript
Thanks @joshgoebel for the suggestion!
I found that in the development environment, the development environment should be able to directly use the language of /highlight.js/lib/languages/, but in the production environment, due to the use of webpack packaging, we have to customize the hljs object, the author provides the registration of the javascript highlighting, and here we need to artificially register the other highlighting language, for example, I want to highlight http response, then I need to register http, xml. this will solve the development environment and production environment highlighting style is not the same!
image
image

SFC

<script setup>
import 'highlight.js/styles/atom-one-dark.css'
import 'highlight.js/lib/common'
import hljs from 'highlight.js/lib/core'
import hljsVuePlugin from '@highlightjs/vue-plugin'
import http from 'highlight.js/lib/languages/http'
import xml from 'highlight.js/lib/languages/xml'
hljs.registerLanguage('http', http)
hljs.registerLanguage('xml', xml)
const highlightjs = hljsVuePlugin.component
import { ref } from 'vue'
const httpResponse = ref('')
const 
</script>
<template>
  <div>
    <highlightjs autodetect :code="httpResponse" />
  </div>
</template>

@byAaronLuo
Copy link
Author

import 'highlight.js/lib/common' is ignored in package. The second image hightlight the code as javascript. You should register the HTML language to highlight the code.
Yeah. Thanks, I got solved this question that is code highlighted the HTTP RESPONSE
But new issue is json 😂 i have already registered json
in the development environment json is rendered to css, but in the production, the json is rendered to json😂
i dont know why🥺🥺🥺

@byAaronLuo
Copy link
Author

For Json Issue

<script setup>
import 'highlight.js/styles/atom-one-dark.css'
import 'highlight.js/lib/common'
import hljs from 'highlight.js/lib/core'
import hljsVuePlugin from '@highlightjs/vue-plugin'
import http from 'highlight.js/lib/languages/http'
import xml from 'highlight.js/lib/languages/xml'
import json from 'highlight.js/lib/languages/json'
hljs.registerLanguage('http', http)
hljs.registerLanguage('xml', xml)
hljs.registerLanguage('json', json)
const highlightjs = hljsVuePlugin.component
const obj = { a: '123', b: '456' }
const jsonOfObj =  JSON.stringify(obj)
const 
</script>
<template>
  <div>
    <highlightjs autodetect :code="jsonOfObj" />
  </div>
</template>

dev:
image

production
image

i need render http and json ✅
In a production environment, do I have to register every code that I want to highlight, and isn't that a pain what so trouble?

@Trinovantes
Copy link
Contributor

@joshgoebel I think some bundlers ignore side effect imports and only look at package.json's sideEffects field. I think you need to add ./lib/common.js to highlight.js package.json.

@xiaomaiyun
Copy link

#44 (comment)

@xiaomaiyun
Copy link

#38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants