• Hi All,

    In a not-completely-unrelated field…

    I use Powergui for my PS scripting.. and it makes the code very nice, (indentations, colour formatting etc).

    However, when I try to post it to my blog (in wordpress).. the results can be very messy.

    First, and most obvious, posting it via WORD makes it look very messy because of all the extra HMTL word does.
    Second, posting to notepad and up loses all the font and formatting.

    I managed to get it to go up to wordpress in the right font and colours by using “cut and paste from PG to word… save word as HTM… open it in explorer, cut and paste it into Writer, post up via writer”. Which as you can see is very messy.

    In fact, even having done that, it then wrapped the code lines around the pagewidth such that it failed when copied back into PGui.

    Does anyone have an idea on how I can nicely cut and paste formatted powershell code into wordpress, (I’ve seen sometimes it is in a little window with a horizontal scroll bar)

    Thanks!

    Gavin

Viewing 9 replies - 1 through 9 (of 9 total)
  • posting it via WORD makes it look very messy because of all the extra HMTL word does

    Don’t paste content from Microsoft Word into WordPress as the pasted text will also contain Word’s own formatting. Sooner or later, this formatting will stop your pages from being displayed correctly (if at all) in Internet Explorer. If you cannot possibly manage without Word, paste your text into NotePad (or another text editor) first, then copy from NotePad into WordPress. Or use Windows LiveWriter.

    Are you correctly escaping all of your code before pasting it into WP from (say) NotePad? Are you wrapping it it <pre><code></code></pre> tags? Have you looked at any code syntax highlighting plugins?

    Thread Starter Gavin Williams

    (@gavin-williams)

    Hi esmi,

    Yes thanks for that … I definitely saw all the posts around on the internet saying “don’t post from word”. Message received loud and clear.

    However, what no-one seems to be able to answer is how to cut and paste while keeping the formatting. I don’t want to have to chagne font manually, and then manually recolour each of the words in the code green or red etc. And as I said, using livewriter got there eventually, but with linebreaks where there should not be.

    Are you wrapping the code <pre><code></code></pre> tags?
    Have you looked at any code syntax highlighting plugins?

    Thread Starter Gavin Williams

    (@gavin-williams)

    no.. I’m a bit of a newbie at this stuff..

    what is

    ?
    
    And what are the code syntax highlighting plugins?
    
    I'm not afraid of doing legwork/research myself but I guess I just need the first kind of directional pointers

    Thread Starter Gavin Williams

    (@gavin-williams)

    Hey… something just happened on my last post!! 🙂

    It looks like it’s doing the right stuff wr//t scrollbars

    now if you can explain how/why it did that it will help.

    something just happened on my last post!

    You did not post code tags between backticks or use the code button.

    Thread Starter Gavin Williams

    (@gavin-williams)

    ok.. I installed the syntax highlighter and it is now putting the nice code colours on it..
    It seems that I can do something similar with
    ‘[sourcecode language ="powershell"]
    [/sourcecode]‘

    However the next strange thing is that when I paste two things happen.

    1. All the indentations are lost
    2. Doing a mouse-drag highlight copy/paste pastes it back into my script editor as one long line with not linebreaks.

    Am I missing something easy or else do I need to contact the plugin writer?

    PS: thanks for help so far!

    Try wrapping the code in <pre><code></code></pre> HTML tags.

    http://www.w3schools.com/tags/tag_pre.asp
    http://www.w3schools.com/tags/tag_phrase_elements.asp

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Cutting and pasting powershell code nicely’ is closed to new replies.