Forum code highlighting? (C++, Morrowind, OpenMW)

Discuss and help improve OpenMW's infrastructure: Website, Forums, issue tracker and everything having to do with keeping the lights on with OpenMW.
Post Reply
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Forum code highlighting? (C++, Morrowind, OpenMW)

Post by Jyby »

Since out project is >90% C++, can we get some C++ code highlighting for

Code: Select all

[Code]
[/code] tags?
User avatar
lgromanowski
Site Admin
Posts: 1193
Joined: 05 Aug 2011, 22:21
Location: Wroclaw, Poland
Contact:

Re: Forum C++ code highlighting?

Post by lgromanowski »

Hi,
yes, I'll try to install syntax highlighter this evening
User avatar
psi29a
Posts: 5356
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: Forum C++ code highlighting?

Post by psi29a »

Nice proposal, thanks Jyby and Lgro! :)
User avatar
lgromanowski
Site Admin
Posts: 1193
Joined: 05 Aug 2011, 22:21
Location: Wroclaw, Poland
Contact:

Re: Forum C++ code highlighting?

Post by lgromanowski »

Hi,
I've just added highlight.js but it's not perfect, example:

Code: Select all

#ifndef GAME_MWCLASS_MOBILE_H
#define GAME_MWCLASS_MOBILE_H

#include "../mwworld/class.hpp"

namespace ESM
{
    struct GameSetting;
}

namespace MWClass
{
    /// \brief Class holding functionality common to Creature and NPC
    class Actor : public MWWorld::Class
    {
    protected:

        Actor();

    public:
        virtual ~Actor();

        virtual void adjustPosition(const MWWorld::Ptr& ptr, bool force) const;
        ///< Adjust position to stand on ground. Must be called post model load
        /// @param force do this even if the ptr is flying

        virtual void insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const;

        virtual bool useAnim() const;

        virtual void block(const MWWorld::Ptr &ptr) const;

        virtual osg::Vec3f getRotationVector(const MWWorld::Ptr& ptr) const;
        ///< Return desired rotations, as euler angles.

        virtual float getEncumbrance(const MWWorld::Ptr& ptr) const;
        ///< Returns total weight of objects inside this object (including modifications from magic
        /// effects). Throws an exception, if the object can't hold other objects.

        virtual bool allowTelekinesis(const MWWorld::ConstPtr& ptr) const;
        ///< Return whether this class of object can be activated with telekinesis

        virtual bool isActor() const;

        virtual bool canBeActivated(const MWWorld::Ptr& ptr) const;

        // not implemented
        Actor(const Actor&);
        Actor& operator= (const Actor&);
    };
}

#endif
User avatar
AnyOldName3
Posts: 2668
Joined: 26 Nov 2015, 03:25

Re: Forum C++ code highlighting?

Post by AnyOldName3 »

It might be a good idea to make the language an optional argument to the code tag, as we're likely to get snippets of languages other than C++ here, such as Morrowind scripts.
User avatar
lgromanowski
Site Admin
Posts: 1193
Joined: 05 Aug 2011, 22:21
Location: Wroclaw, Poland
Contact:

Re: Forum C++ code highlighting?

Post by lgromanowski »

AnyOldName3 wrote:It might be a good idea to make the language an optional argument to the code tag, as we're likely to get snippets of languages other than C++ here, such as Morrowind scripts.
Highlight.js uses autodetection for language highlighting (unfortunately MW script is not on the supported languages list), but at this moment it's disabled - C++ language is forced - I'll change it tomorrow.
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: Forum C++ code highlighting?

Post by Jyby »

Thanks Igro

@everyone and @AnyOldName3,

I wonder if we can work with highlightjs and write a highlighter for MW / OpenMW script.

http://highlightjs.readthedocs.io/en/la ... uests.html
User avatar
silentthief
Posts: 456
Joined: 18 Apr 2013, 01:20
Location: Currently traversing the Ascadian Isles

Re: Forum C++ code highlighting?

Post by silentthief »

Jyby wrote:Thanks Igro

@everyone and @AnyOldName3,

I wonder if we can work with highlightjs and write a highlighter for MW / OpenMW script.

http://highlightjs.readthedocs.io/en/la ... uests.html
That would be really helpful.

Was thinking that this should work in the editor as well (Would be nice!!!). Perhaps even with using the (fill in the blank name of an IDE) that when you set up a command with an open brace/quote it populates the command with and open and close, like in code::blocks (programming IDE -- thats right I am trying to learn) if you put a cout << " command, it automatically populates with begin/end quotes and puts the cursor right in between (so it adds the second double quotes, so it becomes cout << "" and puts the cursor between the two sets doublequotes). Pretty sure you see similar setup with geany with regard to braces and other (searching for right term) delimiters (?).

Obviously, what this does is "try" to avoid syntax errors where you forget to leave off an end-brace or and end-quote.

ST
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: Forum C++ code highlighting?

Post by Jyby »

Researching here for scripting reference: http://wiki.theassimilationlab.com/mmw/ ... or_Dummies
Following this guide for making a highlighter: http://highlightjs.readthedocs.io/en/la ... ral-syntax

I haven't given this much effort. Work in progress so far (not sure how successful I'll be):

Code: Select all

{
  case_insensitive: true,
  keywords: 'Begin StartScript StopScript End end if elseif else endif Endif while MessageBox Short Float Set set to',
  contains: [
    {
      className: 'string',
      begin: '\"', end: '\"'
    },
    hljs.COMMENT(
      ';*', // morrowind comments start with ;
      '*\n' // morrowind comments end with \n (do they end with LFRC on other computers?)
    ),
    {
      className: 'ref',
      begin: '\"', end: '\"->'
    }
  ]
}

// TODO: need to represent these

// I think these are represented as *->* in regex.
// Player->RemoveSpell, "Frost_Curse"
// Fargoth->ForceSneak

// Or these examples
// "seen-ref"->StartCombat Player

// if ( ( GetPos x ) == 500 )

// Something like set * to *,*,* for as many comma seperated items
// set temp to 100
Post Reply