Can Chaste Q&A support code formatting?

+2 votes
32 views
asked Oct 12, 2017 by fcooper (390 points)
Would be good to include `code` between ticks, or

```
code blocks
```
etc.  Is this possible?


## Headings, etc would be nice, too

2 Answers

+1 vote
answered Oct 16, 2017 by MichaelClerx (700 points)
selected Oct 17, 2017 by MichaelClerx
 
Best answer

Update

I've removed a bunch of languages so that the code autodetection will be much more likely to recognise C++ (as well as make, cmake, etc.)

Also tweaked the CSS to be less ugly.

The markdown engine used is the same as on stackoverflow, so you create code blocks by indenting everything.

class MyOdeUsingStateVariables : public AbstractOdeSystem
{
public:
    MyOdeUsingStateVariables() : AbstractOdeSystem(1)
    {
        mpSystemInfo = OdeSystemInformation<MyOdeUsingStateVariables>::Instance();
        mStateVariables.push_back(1.0);
    }

    void EvaluateYDerivatives(double time, const std::vector<double>& rY,
                              std::vector<double>& rDY)
    {
        rDY[0] = rY[0]*rY[0] + time*time;
    }
};
commented Oct 16, 2017 by MichaelClerx (700 points)

You may need to refresh after posting code to see the highlighting in effect...

0 votes
answered Oct 12, 2017 by fcooper (390 points)
edited Oct 12, 2017 by MichaelClerx

testing

blah

def f(x):
    # Do stuff
    print('Some Python code')
    x = 0
    for i in xrange(10):
        x += i
    return x
f(5)

That was some code

commented Oct 12, 2017 by fcooper (390 points)
edited Oct 12, 2017 by MichaelClerx

Code block:

auto compare_short_axis = [&](const unsigned& a, const unsigned& b) ->bool
{
    const auto& to_a = p_mesh->GetVectorFromAtoB(centroid, elem_it->GetNode(a)->rGetLocation());
    const auto& to_b = p_mesh->GetVectorFromAtoB(centroid, elem_it->GetNode(b)->rGetLocation());
    return inner_prod(to_a, short_axis) < inner_prod(to_b, short_axis);
};

Welcome to Chaste Q&A, where you can ask questions and receive answers from other members of the community of Chaste developers and users.

See the Chaste wiki for installation instructions, guides and tutorials.

...