Code formatting in a wordpress blog

  • Unknown's avatar

    Hello,

    I published an article here:
    pauladdy.com/2018/02/25/tips-for-xcode-project-configurations-and-swift-code-performance/

    It is ugly.

    I would like to show the code in a better way. I tried to apply the information found at this link, but it does not work.
    https://en.support.wordpress.com/code/posting-source-code/

    The code found at this website is nicely formatted with line numbers, a rectangle, options on top of the rectangle such as copy to clipboard, and we can even scroll horizontally:
    https://www.andrewcbancroft.com/2018/02/24/swift-cheat-sheet-for-iphone-camera-access-usage/

    The blog I need help with is: (visible only to logged in users)

  • Unknown's avatar

    @pauladdydesigner, remember that you can only insert certain amount of code. If you have the WordPress.com Business Plan, you are able to add any type of code. Is there an issue, or a screenshot for this issue you can provide so that I can help?

  • Unknown's avatar

    Hello @alissonwp,

    What is the amount of code I can insert? I have a Premium account…

    Thanks for answering my post,

  • Unknown's avatar

    @pauladdydesigner,

    You can learn more about what codes you can insert: https://en.support.wordpress.com/code/. You cannot post code liks advertisements, because you aren’t on the Business Plan. You also cannot add any code such as any badges or any pictures (that contain code).

    Let me know if you have any more questions

  • Unknown's avatar

    Hi @alissonwp,

    My article is about Swift code performance. I need to add the Swift code to the article. I’ve gone through the link you sent me, and I understand the risk.

    Swift code, is neither JavaScript, not HTML. I would need to use the “objc” language option for the code tag. But it is not working.

    Can you please help?

    Thanks,

  • Unknown's avatar

    @pauladdydesigner,

    Alright. Have you tried switching to the HTML tab when you are editing? If you have the “eligble” code requirements, then it should work. Let me know how that goes.

  • Unknown's avatar

    Hi there @pauladdydesigner, I do not see that SWIFT is one of the languages that is automatically styled when you use the source code parameters mentioned in the support guide you linked to.

    You mentioned you have a Premium upgrade? If so then you also have access to CSS Customization assistance and may wish to post your query in our CSS Customization forum for help by our knowledgeable volunteers and Staff. https://en.forums.wordpress.com/forum/css-customization

    Just in general, other than custom CSS assistance, as a Premium upgrade plan user, you also have access to direct support with Staff by live chat and email when you post your question in the contact form at https://wordpress.com/help/contact

    Hope that helps.

  • Hi there,

    Our syntax highlighter does not support SWIFT, no, but I also don’t see the code-shortcode used on the post you linked to. It looks like you just typed the code itself directly in the editor.

    The other site you linked to is using a plugin called Crayon Syntax Highlighter:

    https://wordpress.org/plugins/crayon-syntax-highlighter/

    You should be able to use that plugin here if you have the Business Plan, but you won’t be able to on the Premium Plan.

    Another option you could consider is to add that code to a Gist instead, and embed that on your site:

    https://en.support.wordpress.com/gist/

  • Unknown's avatar

    Hi,

    @alissonwp,
    Yes, I switch to html and paste the below at the place I want it. Not working :(.

    @justjennifer,
    Thanks, I just posted to the CSS forum. Fingers crossed!
    And thanks for the tip to get extra help, I’ll try it :).

    @kokkieh,
    You rock! The gist tip worked! I will play with it lots to complete my article!

    Code:
    <code lang=”objc”>
    func timeToComplete(operation:()->()) -> CFAbsoluteTime {
    let start = CFAbsoluteTimeGetCurrent()
    operation()

    return CFAbsoluteTimeGetCurrent() – start
    }

    func averageExecutionTime(message: String, numberOfExecutions: Int, operation: () -> ()) {
    var times: [CFAbsoluteTime] = []

    for _ in 0..<numberOfExecutions {
    times.append(timeToComplete(operation: operation))
    }

    let total = times.reduce(0, +)
    let average = total / Double(times.count)
    let min = times.min()
    let max = times.max()

    print(“Average time to complete (message): (String(format: “%.6f”, average)) s.”)
    print(“Minimum time: (String(format: “%.6f”, min!)) s.”)
    print(“Maximum time: (String(format: “%.6f”, max!)) s.”)
    }

  • Fantastic. I’ll mark this as resolved.

  • The topic ‘Code formatting in a wordpress blog’ is closed to new replies.