Does discourse support code blocks?


(Steve Baer) #1

Let’s see how code blocks look in discourse.

import rhinoscriptsyntax as rs
def TestSyntax( a ):
    """This is a document comment about the TestSyntax function"""
    for i in range(10):
        print i, a

Ok, no syntax highlight (yet), but at least things line up how a programmer would expect


vbScript Import Document
(Steve Baer) #2

Oh!!! oneboxing sounds like a great way to embed code
(http://meta.discourse.org/t/what-is-a-onebox/4546)


Here are some sameple gists from github


(Steve Baer) #3

Looks like the github style code syntax works

import rhinoscriptsyntax as rs

def TestSyntax(a):
    """This is a document comment about the TestSyntax function"""
    for i in range(10):
        print i, a

#4

It would be cool to see syntax highlight for Python & Rhinoscript some day. :smiley:


(Steve Baer) #5

This is already supported using github wiki syntax for code block. Use the term vb for RhinoScript blocks

See the syntax highlighting section to see an example of writing a ruby code block
https://help.github.com/articles/github-flavored-markdown#syntax-highlighting


#6

Just a test:

Python

import rhinoscriptsyntax as rs
def SelSomeCrvs():
    crvs=rs.GetObjects("Select curves",4,preselect=True,select=False)
    if not crvs: return

OK, not bad, doesn’t match the python forum’s coding nor the script editor, but very readable

VBscript

Option Explicit
Sub ColorToObject()	
	Dim arrAllObjs,intObjColor,i	
			
	arrAllObjs=Rhino.NormalObjects	
	If Not IsArray(arrAllObjs) Then	Exit Sub
	
	Call Rhino.EnableRedraw(False)
	For i=0 To UBound(arrAllObjs)  
		intObjColor = Rhino.ObjectColor(arrAllObjs(i))
		Call Rhino.ObjectColor(arrAllObjs(i),intObjColor)	
	Next	
	Call Rhino.EnableRedraw(True)	
End Sub

Call ColorToObject()

Same comment as for python - but nice and readable, that’s the important thing.
–Mitch

Edit: hmm, that’s odd, in the preview box I see color, but when I post, it disappears…?
Ahhh, and now it’s back… bizarre.
Oh, wait… No code box…


(Steve Baer) #7

I definitely know that we can tweak these colors with CSS modifications. I already did something very similar when setting up the wiki


#8

OK, thanks Steve, looking forward to it… --Mitch


#9

@stevebaer how do I get such a colored code-box like in your post?
I can’t find a way how to do this

thx, Tobias


(Steve Baer) #10

Markdown format that looks like

```python
def printhi():
    print "hi"
```

Looks like

def printhi():
    print "hi"

Use the term vb instead of python if you want to display rhinoscript


#11

Thanks Steve