-
Notifications
You must be signed in to change notification settings - Fork 183
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
Allow highlighting in code samples #337
Comments
Hey @ArgentEnergy, I will look into this. If TinyMCE can't do it, there might be an easy way to stop using the codesample plugin and create a custom HTML wrapper. Ghostwriter's reporting engine only cares about the |
Thank you @chrismaddalena! :) This might be another issue but I noticed that code samples, bullet lists, numbered lists, and inline code aren't following the styling in Word. I checked my template and they all have font justified for the font styles but we have to manually do this after exporting. TinyMCE covers the font justify issue for most but not code samples and the lists (bullet or numbered). I don't think it's my template but here's our format:
We're on v3.2.6 right now and plan on moving to version 4 so I'm not sure if this was resolved in a future version yet. |
In a related note, web browsers that have dark-mode enabled struggle to render the highlighting that TinyMCE can apply to non-code elements. I'm not really sure why though - I would imagine that highlighting yellow would always result in it being yellow. If you look closely, you can see there is a slight shift from dark grey to slightly lighter grey, but not much of one. |
@ArgentEnergy did you find out how to highlight lines of code within the codesample plugin? |
@domwhewell-sage No, right now we have to do it manually in the Word document until Ghostwriter supports it. Not sure of the ETA on this feature. You'll have to ask @chrismaddalena. |
I haven't looked into yet. As mentioned above, we'll have to investigate what we can do with TinyMCE. We can't highlight or otherwise style code inside a code block today because it's all wrapped in |
This issue has been labeled as |
This issue is closed because it has been inactive for 14 days since being labeled |
@chrismaddalena Is this on a roadmap to implement at some point in the near future? |
Hi @ArgentEnergy this might help, I have achieved this by modifying the Essentially in the editor you add in a block of text and a inline code the same way and the If the paragraph contains other text/tags aswell as a This way any styles that are children of def text(self, el, *, par=None, style=None, **kwargs):
if par is None:
# Text without a paragraph. If this is just some trailing whitespace, ignore it, otherwise
# report an error.
if el.strip():
raise ValueError(
"found text node that was not enclosed in a paragraph or other block item: {!r}".format(el.text)
)
return
if style and style.get("inline_code"):
self.insert_code(par, el, style)
else:
run = par.add_run()
self.text_tracking.append_text_to_run(run, el)
self.style_run(run, style or {})
def insert_code(self, par, el, style=None):
"""
Add some code with formatting into the report.
If no other code blocks exist within the parent element, the code will be styled as a code block. Otherwise, it will be styled as inline code.
"""
current_el = el
while current_el is not None and current_el.name != "p":
current_el = current_el.parent
if all(child.name in ['code', 'br'] for child in current_el.children):
style["inline_code"] = False
par.style = "CodeBlock"
self.text_tracking.force_emit_pending_segment_break()
run = par.add_run(text)
self.style_run(run, style) Our main use case for this is pasting in HTTP requests/responses from burpsuite and allowing us to highlight areas of the request/response that are important. Here is the source of an rich text editor <p>In the extract below a request was sent to <code>http://host.example.com/user/profile/update</code></p>
<p><code>POST /user/profile/update HTTP/2</code><br /><code>Host: host.example.com</code><br /><code>User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0</code><br /><code>Accept: application/json, text/javascript, */*; q=0.01</code><br /><code>Accept-Language: en-GB,en;q=0.5</code><br /><code>Accept-Encoding: gzip, deflate, br</code><br /><code>Content-Type: application/json</code></p>
<p><code>{</code><br /><code> <span class="highlight" style="background-color: yellow;">"FirstName":"Test",</span></code><br /><code> "LastName":"User",</code><br /><code> "Email":"testuser@example.com",</code><br /><code>}</code></p> |
Yes, this is on the road map for us to look at. @domwhewell-sage Is that all the code you added for highlighting in the code sample? |
It looks like this works after changing You have multiple |
One option is adding |
Hi @chrismaddalena, yes these are the changes I made to the report writer module to get it to process I am pasting the code into the editor straight from burpsuite so perhaps that is where it's creating the From here I'm not sure if we can modify the code sample plugin to insert the code like this or we need todo a custom plugin to insert the code like this which will also allow is todo syntax highlighting. |
OK, interesting! We can probably include this in a release so it's possible to do, even if how you add your code sample may add newlines or not. I'm going to think about the Our goal is writing reports, not HTML webpages, so it's unlikely you'd ever want to break a line in the middle of a paragraph. That makes me want to explore the custom code block/sample plugin idea. |
I think a better way - which I'm gonna try to implement - is to wrap the code segment in a blockquote, and turn the A custom TinyMCE plugin would be cool, but I'm not sure if it's worth the effort. |
Alex worked on a different approach with PR #487. Here is an example they shared of it: You can style with "rich code" to add formatting to a code block. @domwhewell-sage If you have some time to check it out, please let us know if this does what you're looking for. I think it does what you wanted and then some. |
Hi both,
In both cases it generated correctly appearing how it did in the editor Could we swap the "Rich code" menu item onto the menu bar in place of the "Code Sample", with the |
Yeah, I'm not opposed to removing the built-in code sample functionality. The only argument I can see against it is that code samples theoretically support automatic syntax highlighting, but I don't think we ever set that up. |
Unlike TinyMCE's built in code snippets, these support formatting the text inside of the code, for highlighting certain sections. Implements GhostManager#337
We could also run a syntax highligher on the server. But that's for the future. (Also we'd probably keep the code snippet plugin loaded, to support existing uses, but we can hide the buttons) @chrismaddalena Thoughts? |
Based on Chris's feedback, I've updated the PR to replace the toolbar Code Snippet with the new Rich Code. The Code snippet feature is still available via the Insert menu. |
I merged the PR and the feature will be in the next release. |
We use code samples (have a specific Word styling for code samples) for HTTP requests and one of the pain points we have is GW doesn't offer the ability to highlight text inside them. The mark HTML tag is stripped if manually adding into the source code under the code HTML tag. This looks to be a dependency issue relying on TinyMCE's code sample plugin that relies on Prism.js.
Is it possible to fix this issue with having a custom Prism.js file to not strip the mark tags?
https://www.tiny.cloud/docs/plugins/opensource/codesample/#codesample_global_prismjs
PrismJS/prism#879
We have to manually do the highlighting in Word. This becomes tedious if you did the manual work already and a report change happens that makes us regenerate the report again.
The text was updated successfully, but these errors were encountered: