Cancel
Showing results for 
Search instead for 
Did you mean: 

Preserving code snippets in posts

Siemens Legend Siemens Legend
Siemens Legend

If you want to include screen dump text/code in the post, you can utilize the insert code component in the Rich Text editor. 

 

insert code.jpg

 

 

It will include the highlighted code like this:  

 

. Your code goes here...
.
.
UgSession::initialize ( )
// Your Open C++ code here
UgSession::terminate ( )
.
.
.

 

 

Source:  Lithium community (password required) 

 

Jerry

 

- - - -
Jerry Sarfati
Siemens PLM Software
5 REPLIES

Re: Preserving code snippets in posts

Siemens Phenom Siemens Phenom
Siemens Phenom

Actually, you can copy/paste code from Visual Studio

directly into the Rich Text window, because Vis Studio places RTF on the Clipboard when you do a Cut or Copy. Pasting messes up the spaces, but it preserves colors and font, which is nice.

 

Dim d, x, y As Double

Dim pt As NX.Point

Dim nU = 100 

Dim nV = 70

Dim pts(nU, nV) As Position

 

Also, as far as I can see, code that you write in the special "Insert Code" window just gets sandwiched between <pre> and </pre> tags, so you could easily just type this HTML yourself, if you wanted.

山田
yamada

Re: Preserving code snippets in posts

Experimenter
Experimenter

Maybe I was a little to quick with my kudo Smiley Tongue

 

I couldn't reproduce the behaviour @Yamada describes.

I tried Visual Studio 2010 Professional, Visual Studio 2015 Express and various methods in Notepad++ (found in Menu -> Plugins -> NppExport) to copy RTF/formatted Text into the forum's editor using Firefox, Internet Explorer and Chrome.

 

The most I got was the pasted text being wrapped in a <pre>-section automatically. Often the formatted text wouldn't even show up in the editor at all (though pasting to e.g. Word worked fine with preserved formatting).

 

Is there still a way to get syntax highlighted code in the forum? Or will it boil down to manually editing the HTML?

 

Would be really cool to have some kind of shortcut to paste formatted/highlighted code! Smiley Happy

Re: Preserving code snippets in posts

Siemens Phenom Siemens Phenom
Siemens Phenom
I can't get it to work, now, either. But I'm sure that it used to work. As you can see, I managed to get colorized code in my post above, and I certainly didn't type all the RTF gibberish myself. Anyway, I agree that the ability to post colorized code would be very nice.
山田
yamada

Re: Preserving code snippets in posts

Experimenter
Experimenter

Sorry, @Yamada, I think I worded my reply a bit wrong. I did not at all mean to imply that your post was wrong. It was just a funny moment, when I read your post, thought "great tip, finally!", kudoed you, and then it didn't work Smiley Very Happy

 

I suppose, that the feature propably has been removed during some redesign process (as the screenshots in the first post are outdated, too). Hopefully this gets another update, soon Smiley Happy

Re: Preserving code snippets in posts

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi @Merlin2001,

 

I just verified that text copied from VS 2017 and pasted into the Rich Text field using IE 11 preserves the colors and font:

 

Imports System

Module NXJournal

Public Sub Main(ByVal args As String())

Dim thePDF As String = "Z:\IR\8966616\dir with spaces\webstera_toycar_assy.pdf"

' the %22s in the line below put double quotes around the file path

Shell("cmd /c %22" & thePDF & "%22")

End Sub

End Module

 

Text copied in using Firefox, Chrome and Opera did not.

Regards, Ben