-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Setting up syntax highlighting of code section #5259
Setting up syntax highlighting of code section #5259
Conversation
f86242b
to
0c57874
Compare
(rebased) |
👋 @shockey I know there is right now some conflict, but I'll like some feed back before updating Pull request. Thanks in advance :) |
Can we please get this merged :-( Having no code highlighting is such a bad experience in an otherwise so beautiful tool. It's all there, ready to be used, it just takes a review and a merge :-) |
I would love for this to get merged, a really needed feature! |
I am interested in this capability. It just seems like it would make for a better looking UI. |
0c57874
to
e9e9ce4
Compare
👋 @shockey & @webron or other like @tim-lai and @swaggerhub-bot , I updated the PR to solve conflict that arose during last year. I really hope you will consider the PR and I will try to reach you on other channel. however the build would likely fail:
|
@AdrieanKhisbe Thanks for the PR! Catching up on long standing PRs... This looks promising. A couple of notes/concerns:
|
Hello @tim-lai ! :) To address your concerns, here is what I have in mind:
What do you think about these? |
Thinking about this more, it would better to write this as a plugin. Then we could be more agnostic to the libraries used, switch out libraries as needed, and potentially even offer users a choice of highlighters. The plugin could have its own set of config options.
It's not a hard "no" for
We may do code-splitting in the future. |
@tim-lai I'm really not sure it should be a plugin 🤔 This should come built-in, and work out-of-the-box (as it was for swagger v1). For some extra feature opting for a plugin is totally legitimate. However for syntax highlighting of curl command and payloads, I'm really not sure. In my opinion it's really at the core of the experience swagger-ui brings. Also, I think far more efforts are needed to convert this to a plugin, than to replace |
@AdrieanKhisbe Fair comments. Let's move forward without the plugin concept. Thanks. |
Okey @tim-lai, I will go forward based on your inputs :) Also, I might rewrite the whole branch. If you prefer me to keep the original commits, don't hesitate to tell me. :) |
e9e9ce4
to
5329129
Compare
Hello @tim-lai, I did rewrite the PR using Documentation is still be done, I wait for a validation on the approach and signature. 📖 Also, choice of themes could be review or extended. 🎨 |
@AdrieanKhisbe Functionally, this looks good, and it's also good that it's not pulling from a cdn. Looking forward to the documentation and screenshots. |
Okey @tim-lai, I'll handle that then! :) I might come back to you if I'm not sure about were to add documentation. 📖 (I will start to search from |
theme selection was introduced, and 5 highlight themes picks in a randomly arbirtrar manner list: https://github.com/highlightjs/highlight.js/tree/master/src/styles, demo: https://highlightjs.org/static/demo/
adding react-syntaxt-highligth in a25aefc tiped the scale over limit by very little. This commit adjust limit. (2.4% increase)
Screenshot was compressed to have similar size than previous swagger-ui3.png
5329129
to
0ed23c5
Compare
Hello @tim-lai :) I took care of the conflict via a rebase, and also:
Tell me if you think of other places that should be updated. |
Thanks a lot @tim-lai for you help to have to land!! :) |
bump from 3.12 to 3.30 that includes swagger-api/swagger-ui#5259
@AdrieanKhisbe is there opt-out ability for the syntax highlighting? kind of ugly imo, sorry :). |
Hello @SledgeHammer01, Most simple way is to add For more details, see last settings of display section in documentation |
Hi @AdrieanKhisbe, I am using the following configuration which doesn't seem to disable the syntaxHighlight. (swagger-ui version 3.34.0) Thank you window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "https://petstore.swagger.io/v2/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
syntaxHighlight: false,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// End Swagger UI call region
window.ui = ui
} |
@mariem-89, the Could you try the explicit: |
In fact after several tests, i can confirm it is not working in the request Body section. But i was only able to disable the syntax Highlight of the response section: As you can see in the following screenshot. Do you have any solution or workaround ? I guess there is also the parameter name is not correct in the documentation](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#parameters). But correct me if am wrong. Thank you for your help |
Indeed @mariem-89 there seems to be a glitch for the body section, config might not be forwarded correctly or something like. |
Unfortunately I don't reproduce neither on my old branch (the one of that PR), nor on current master. Just adding What version are you using exactly? |
Thank you for your quick reply. openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: 'http://localhost:8080'
description: Generated server url
paths:
/values/data:
post:
tags:
- hello-controller
operationId: list
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/TrackerData'
responses:
'200':
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/TrackerData'
components:
schemas:
TrackerData:
required:
- timestamp
- trackerId
- value
type: object
properties:
trackerId:
type: string
example: the-tracker-id
timestamp:
type: string
format: date-time
example: '2018-01-01T00:00:00Z'
value:
type: number
description: The data value
format: double
example: 19 I get the following result, where the syntax highlighting has not been disabled on the |
Update: you can skip this message to next one 😁
|
@mariem-89 I just managed to reproduce, adding your spec to dist, serving the files and updating url I will look what is specific to that spec, and where is the non standard path in which config is not injected. (which results in default behavior to activate the syntax highlight). |
… Examples 🔌 As a result, syntax highlight could not be disabled be disabled or configured in that elements
…o Examples 🔌 As a result, syntax highlight could not be disabled be disabled or configured in that elements
@mariem-89 I founded the cause, |
Thank you very much for your help. Really appreciated. |
* Complement #5259, getConfigs was not correctly forwarded to Examples. As a result, syntax highlight could not be disabled be disabled or configured in that elements
Restore syntax highlighting of the code section
Description
I introduce react-lowlight based on highlight to take care of syntax highliting.
To do so I updated the
highlight-code
component, and also thecurl
one.To modify the
curl
I had to tweak the copy mecanism. Now instead to click on the area, there is a textCopy Command
that will copy command on click.(an icon where be preferable, but I would need some guidance)
Motivation and Context
Because syntax highligting 🌈 😉
Fixes #3189
How Has This Been Tested?
I tested it locally, and it was working as it should.
I'll see if it breaks the build, and fix it adequately if needed
Screenshots (if appropriate):
Checklist
My PR contains...
src/
is unmodified: changes to documentation, CI, metadata, etc.)package.json
)My changes...
Documentation
Automated tests