progsource / maddy

C++ Markdown to HTML header-only parser library
MIT License
202 stars 40 forks source link

[Bug][Markdown]: My markdown is not being parsed correctly #47

Open asu4net opened 1 year ago

asu4net commented 1 year ago

Operating System

Windows

Compiler

MVSC

Compiler flags

std:c++17

maddy version

1.2.0 (latest)

Minimal Mardown example

Zote Engine

Zote is a 2D Game Engine developed for my final university assignment.

Features

Build

Hello Zote

Window setup

Zote doesn't have an Editor yet. So if you want to create a brand new game some basic setup is required. In order to start writing code go to the Game project and open Game.cpp. Then, inside the Run method, create your first Window and call his Init() and StartLoop() methods.

Ref<Window> myWindow = MakeRef<Window>();
myWindow->Init();

//Your scene setup code goes HERE.

myWindow->StartLoop();

The window must be constructed as a reference. The Ref syntax is just a normal shared pointer. The StartLoop() method initialises the window loop. So if you write code after that function it won't execute until the Zote Window get's closed.

Running the application now should open an empty grey window.

First entity

In order to create entites a Scene instance is required. At this point you can't create multiple scenes. After the scene initialisation you can call the scene CreateEntity() method and start adding components to it.

Scene myScene(myWindow);
Entity zote = myScene.CreateEntity();
zote.AddComponent<SpriteComponent>("Textures/alex.png");

At this point by running the application you should be experiencing the pleasure of being in the presence of Alex, the creator of this high tech engine.

Script System

The script system is quite similar to the Unity Monobehiavours. Behind the scenes works with the ECS pattern but the usage is more simple. To start using scripts you must to add the ScriptComponent to your entity.

Then, you can create your script in new .h and .cpp separated files. The next example will show how to create a script that changes between two sprites:

SwitchBetweenSprites.h

#pragma once
#include <ZoteCommon.h>

using namespace Zote;

class SwitchBetweenSprites : public Script
{
public:
    cstr pathA = "Textures/csharp.png";
    cstr pathB = "Textures/cpp.png";
    float timeToSwitch = 1;

    void Start() override;
    void Update(float deltaTime) override;

private:

    Entity thisEntity;
    bool change = false;
    float currentTime = 0;

};

SwitchBetweenSprites.cpp

#include "SwitchBetweenSprites.h"

void SwitchBetweenSprites::Start()
{
    LOG("Script SwitchBetweenSprites started");
    thisEntity = GetEntity();
}

void SwitchBetweenSprites::Update(float deltaTime)
{
    auto& spriteComponent = thisEntity.GetComponent<SpriteComponent>();

    currentTime += deltaTime;

    if (currentTime < timeToSwitch)
        return;

    currentTime = 0;

    cstr path = change ? pathA : pathB;
    spriteComponent.AddTexture(path);
    change = !change;

    LOG("Sprite texture updated to: " << path);
}

When the script is ready go back to Game.cpp and don't forget to write the preprocessor statement, for this example: #include "Scripts/SwitchBetweenSprites.h". By using the AddScript() method you can attach the script to the script component. It is possible to call this function with multiple scripts to attach them to a single Entity. It's mandatory to create the script instance as a pointer. This is the final code inside the Run() method.

Ref<Window> window = MakeRef<Window>();
window->Init();

Scene scene(window);

Entity myEntity = scene.CreateEntity();
myEntity.AddComponent<SpriteComponent>();

auto& myEntity_Scripts = myEntity.AddComponent<ScriptComponent>();
myEntity_Scripts.AddScript(new SwitchBetweenSprites());

window->StartLoop();

By hitting the run button you should see, in first place a blank quad, and then the csharp and cpp textures switching in the screen.

What is not working? What did you try?

For the provided markdown is generting a unexpected outcome. For example, the headers are not being parsed.....

# Zote Engine

Zote is a 2D Game Engine developed for my final university assignment.




## Features
- Scene
- Camera (Orthographic and Perspective)
- Entities and Components
- 2D Rendering
- 2D Physics
- Scripting System
- Build System
- Input System




## Build
- Ensure you are using Windows 64-bit
- Ensure you have Visual Studio 2022 installed
- Clone this project
- Open the project's root folder
- Run GenerateProjects.bat
- Open Zote.sln
- Build the Game project
- Hit the play button and ✨Enjoy✨




## Hello Zote



### Window setup
Zote doesn't have an Editor yet. So if you want to create a brand new game some basic setup is required. In order to start writing code go to the Game project and open Game.cpp. Then, inside the Run method, create your first Window and call his Init() and StartLoop() methods.

`
Ref myWindow = MakeRef();
myWindow->Init();

//Your scene setup code goes HERE.

myWindow->StartLoop();
`

The window **must** be constructed as a reference. The Ref syntax is just a normal shared pointer. The StartLoop() method initialises the window loop. So if you write code after that function it won't execute until the Zote Window get's closed.


Running the application now should open an empty grey window.



### First entity
In order to create entites a Scene instance is required. At this point you **can't** create multiple scenes. After the scene initialisation you can call the scene CreateEntity() method and start adding components to it.

`
Scene myScene(myWindow);
Entity zote = myScene.CreateEntity();
zote.AddComponent("Textures/alex.png");
`


At this point by running the application you should be experiencing the pleasure of being in the presence of Alex, the creator of this high tech engine.



## Script System



The script system is quite similar to the Unity Monobehiavours. Behind the scenes works with the ECS pattern but the usage is more simple. To start using scripts you must to add the ScriptComponent to your entity.

Then, you can create your script in new .h and .cpp separated files. The next example will show how to create a script that changes between two sprites:



SwitchBetweenSprites.h
`
#pragma once
#include

using namespace Zote;

class SwitchBetweenSprites : public Script
{
public:
cstr pathA = "Textures/csharp.png";
cstr pathB = "Textures/cpp.png";
float timeToSwitch = 1;

void Start() override;
void Update(float deltaTime) override;

private:

Entity thisEntity;
bool change = false;
float currentTime = 0;

};
`
SwitchBetweenSprites.cpp
`
#include "SwitchBetweenSprites.h"

void SwitchBetweenSprites::Start()
{
LOG("Script SwitchBetweenSprites started");
thisEntity = GetEntity();
}

void SwitchBetweenSprites::Update(float deltaTime)
{
auto& spriteComponent = thisEntity.GetComponent();

currentTime += deltaTime;

if (currentTime < timeToSwitch)
return;

currentTime = 0;

cstr path = change ? pathA : pathB;
spriteComponent.AddTexture(path);
change = !change;

LOG("Sprite texture updated to: " << path);
}
`
When the script is ready go back to Game.cpp and don't forget to write the preprocessor statement, for this example: #include "Scripts/SwitchBetweenSprites.h". By using the AddScript() method you can attach the script to the script component. It is possible to call this function with multiple scripts to attach them to a single Entity. It's mandatory to create the script instance as a **pointer**. This is the final code inside the Run() method.
`
Ref window = MakeRef();
window->Init();

Scene scene(window);

Entity myEntity = scene.CreateEntity();
myEntity.AddComponent();

auto& myEntity_Scripts = myEntity.AddComponent();
myEntity_Scripts.AddScript(new SwitchBetweenSprites());

window->StartLoop();
`
By hitting the run button you should see, in first place a blank quad, and then the csharp and cpp textures switching in the screen.ññññ

progsource commented 1 year ago

I'll investigate this. In the meantime for displaying the Markdown example here on GitHub as code example, I recommend indenting it by 4 spaces (doesn't work in maddy yet, but should on GitHub ;) )

progsource commented 1 year ago

For maddy to be able to parse headlines, they have to be preceded by an empty line.

some paragraph text

# my headline

some other text

The lists * should be on the start of the line, each list item should not be separated by an empty line, but follow directly after each other.

some paragraph

* list item 1
* list item 2
* list item 3

some more text

Currently there is no inline parsing happening inside of headlines. For that I will prepare something for an upcoming maddy version.

In the line where the **pointer** is not parsed to a strong element - this has to do with how the regex is handling stuff regarding having inline codes in the same line. This might be a little bit more difficult to fix in maddy 1.*, but I will definitely keep it in mind for 2.*.

progsource commented 1 year ago

Headline inline parsing is available now with 1.3.0

asu4net commented 1 year ago

Thank you!

El sáb, 26 ago 2023 a las 13:38, Petra Baranski @.***>) escribió:

Headline inline parsing is available now with 1.3.0 https://github.com/progsource/maddy/releases/tag/1.3.0

— Reply to this email directly, view it on GitHub https://github.com/progsource/maddy/issues/47#issuecomment-1694304952, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOZDUPSHQ5IMLHWNGKXB37TXXHN2FANCNFSM6AAAAAA3YBNHPY . You are receiving this because you authored the thread.Message ID: @.***>