Forum Discussion

A11ey's avatar
A11ey
Former Employee
2 years ago

How to use the Code Block feature when posting.

 

Using a code block instead of simply pasting text has several advantages, especially when you're sharing code or technical content. Using this instead of just pasting your code as text will improve readability, accessibility syntax highlighting, preserves whitespace, takes up less character space and makes it much easier to copy & paste code.

  • Log In: Make sure you are logged in to your LM Community account.
  • Create or Edit a Post: You can either create a new post or edit an existing one where you want to add a code block.
  • Access the Text Editor
  • Select the 3 dots … 
  • Select {;} Insert/Edit Code Sample

​ 

  • A pop up box will appear, search for the Language you want to insert.
  • Paste or Type Your Code: Once 
  • When complete click “Insert”.
  • You can also add any verbiage before or after your code block.

 

  • If you need to edit your post/code block, click the Gear icon on the top right of your post,  select edit, make your updates and then save/publish. 

 

  • If you are editing a Reply, 






 

  • Some candid feedback: This is particularly cumbersome. I would strongly prefer to be able to use traditional markdown for these blocks. Slack and Atlassian products are great references for this, as simply typing ``` creates a free-form code-block field that I can easily copy/paste into.

    The more time I spend keeping my hands on my keyboard = less time I spend formatting my posts = more time spent on actual Community content :) 

  • A11ey's avatar
    A11ey
    Former Employee

    @Austin Culbertson totally understand!  Community platforms that have editors similar to this require the “Insert Code”. I know the Atlassian products support this, but last I was on their Community you have to select insert code.  I’ll look into our new platform, which is the same as Atlassian’s, and see if there is a feature or request to be able to do this! 

  • mray's avatar
    mray
    Icon for LM Conqueror rankLM Conqueror

    Markdown is the de facto standard and super convenient. This method of clicking the code option in the overflow menu isn’t too bad honestly -- could be worse. My biggest gripe is it just looks bad…

    Here’s some Python code and now my eyes hurt

    from __future__ import print_function
    import time
    import logicmonitor_sdk
    from logicmonitor_sdk.rest import ApiException
    from pprint import pprint


    # API authorization
    configuration = logicmonitor_sdk.Configuration()
    configuration.company = 'portalname'
    configuration.auth_type = 'Bearer'
    configuration.bearer_token = 'lmb_xxx'

    # create an instance of the API class
    api_instance = logicmonitor_sdk.LMApi(
    logicmonitor_sdk.ApiClient(configuration))

    body = logicmonitor_sdk.models.Device(
    name="1.1.1.1",
    display_name="dummy",
    preferred_collector_id=42
    )

    try:
    # add device
    api_response = api_instance.add_device(body)
    print("Response:")
    pprint(api_response)
    except ApiException as e:
    print("Exception when calling LMApi->addDevice: %s\n" % e)

    Atlassian Community’s code block also doesn’t look that great tbh but it is easier on the eyes I guess:

    Can we have blocks in numbered lists here?

    1. Some text plus that same confluence code in the screenshot
      spaces = confluence.get_all_spaces(start=0, limit=500, expand=None)
      slist = spaces['results']
      for s in slist:
      print(s['key'], s['name'], s['type'])
    2. Ahh neat! 
      print("but my vote is still for full markdown support")
  • A11ey's avatar
    A11ey
    Former Employee

    Stay tuned!  We are the final stages of acquiring a new Community Platform.  I tested their code block feature with a sample of Python and this is how it looked:

    Better?

  • mray's avatar
    mray
    Icon for LM Conqueror rankLM Conqueror

    I’ll also add that while trying to submit that comment, I kept getting a “Something went wrong error” and it wiped my comment from the text box. Luckily I could ctrl+z to get it back but that might not always work.