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

This is the place to discuss the Wiki contents, forum issues, themes and to propose site-related features and ideas.
Post Reply
User avatar
Jyby
Posts: 406
Joined: 10 Dec 2013, 04:16

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

Post by Jyby » 07 May 2017, 23:28

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

Code: Select all

[Code]
[/code] tags?
Macbook Air 2013 - 1.7GHz Intel i7 - 8 GB - 512 GB SSD - Intel HD 5000
Windows 10 PC - 4GHz Intel i7 - 16 GB - 512 GB SSD - EVGA GTX 1060 SSC

User avatar
lgromanowski
Site Admin
Posts: 1143
Joined: 05 Aug 2011, 22:21
Location: Wroclaw, Poland
Github profile: https://github.com/lgromanowski
Contact:

Re: Forum C++ code highlighting?

Post by lgromanowski » 08 May 2017, 05:50

Hi,
yes, I'll try to install syntax highlighter this evening
best regards,
Lukasz

User avatar
psi29a
Posts: 3395
Joined: 29 Sep 2011, 10:13
Github profile: https://github.com/psi29a/
Contact:

Re: Forum C++ code highlighting?

Post by psi29a » 08 May 2017, 08:17

Nice proposal, thanks Jyby and Lgro! :)

User avatar
lgromanowski
Site Admin
Posts: 1143
Joined: 05 Aug 2011, 22:21
Location: Wroclaw, Poland
Github profile: https://github.com/lgromanowski
Contact:

Re: Forum C++ code highlighting?

Post by lgromanowski » 08 May 2017, 20:15

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
best regards,
Lukasz

User avatar
AnyOldName3
Posts: 458
Joined: 26 Nov 2015, 03:25

Re: Forum C++ code highlighting?

Post by AnyOldName3 » 08 May 2017, 20:38

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: 1143
Joined: 05 Aug 2011, 22:21
Location: Wroclaw, Poland
Github profile: https://github.com/lgromanowski
Contact:

Re: Forum C++ code highlighting?

Post by lgromanowski » 08 May 2017, 20:54

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.
best regards,
Lukasz

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

Re: Forum C++ code highlighting?

Post by Jyby » 08 May 2017, 22:09

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
Macbook Air 2013 - 1.7GHz Intel i7 - 8 GB - 512 GB SSD - Intel HD 5000
Windows 10 PC - 4GHz Intel i7 - 16 GB - 512 GB SSD - EVGA GTX 1060 SSC

silentthief
Posts: 263
Joined: 18 Apr 2013, 01:20

Re: Forum C++ code highlighting?

Post by silentthief » 10 May 2017, 06:10

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: 406
Joined: 10 Dec 2013, 04:16

Re: Forum C++ code highlighting?

Post by Jyby » 11 May 2017, 06:52

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
Macbook Air 2013 - 1.7GHz Intel i7 - 8 GB - 512 GB SSD - Intel HD 5000
Windows 10 PC - 4GHz Intel i7 - 16 GB - 512 GB SSD - EVGA GTX 1060 SSC

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest