Giter Site home page Giter Site logo

imgui_markdown's People

Contributors

claasjg avatar dougbinks avatar juliettef avatar leonardodemartino avatar mekhontsev avatar ocornut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imgui_markdown's Issues

Implicit fallthrough warning/error

I'm not sure the best way to resolve this issue in the repo, but when compiling with GCC on Ubuntu with options -Wall -Wextra -pedantic -Wno-unknown-pragmas -Werror:

In file included from /some/folder/work/myproj/myproj/src/main.cpp:20:
/home/runner/work/iragui/iragui/libs/imgui_markdown/imgui_markdown.h: In function ‘void ImGui::Markdown(const char*, size_t, const ImGui::MarkdownConfig&)’:
/home/runner/work/iragui/iragui/libs/imgui_markdown/imgui_markdown.h:726:33: error: this statement may fall through [-Werror=implicit-fallthrough=]
  726 |                                 if( em.sym == c )
      |                                 ^~
/home/runner/work/myproj/myproj/libs/imgui_markdown/imgui_markdown.h:736:25: note: here
  736 |                         case Emphasis::RIGHT:
      |                         ^~~~
cc1plus: all warnings being treated as errors

This warning can be handled in C++17 with the [[fallthrough]] attribute (in fact the linked example is almost this very case!). However, prior to C++17 unknown attributes were not guaranteed to be ignored, so using this attribute could lead to warnings with other toolchains.

I guess one messy solution might be:

#if __cplusplus >= 201703L
    [[fallthrough]]
#endif

EDIT:

Actually this fix

case Emphasis::MIDDLE:
	if( em.sym == c )
	{
		em.state = Emphasis::RIGHT;
		em.text.stop = i;
		// pass through to case Emphasis::RIGHT
		[[fallthrough]]; 
	}
	 else
	{
		break;
	}
case Emphasis::RIGHT:

Results in MSVC warning:

warning C4468: the [[fallthrough]] attribute must be followed by a case label or a default label

Icon

Here You show "This is an icon"

I would like to see the code for that since I would like to use ICON_FA_STAR in the markdown but cannot get it to work

Thank you in advance

Example segfaults

Hi, im trying this library for my project but when i call the ImGui::Markdown(...) it segfaults.
here's a snippet of my code (with few modifications as i dont need image and links in markdown so i've removed the corresponding callbacks)

#include "imgui.h"
#include "imgui_markdown.h"
#include "IconsFontAwesome5.h"
//font.cpp
//the following are static variables declared in font.hpp
ImFont* Font::H1;
ImFont* Font::H2;
ImFont* Font::H3;
ImGui::MarkdownConfig Font::md_config;
const char* Font::connected_path = "assets/fonts/test.ttf";

//font loading
const float md_font_size = 12.0f;
ImGuiIO& io = ImGui::GetIO();
// io.Fonts->Clear(); //not called as i load many fonts prior to loading fonts for markdown
io.Fonts->AddFontFromFileTTF(Font::connected_path, md_font_size);
Font::H2 = io.Fonts->AddFontFromFileTTF(Font::connected_path, md_font_size);
Font::H3 = md_config.headingFormats[1].font;
Font::H1 = io.Fonts->AddFontFromFileTTF(Font::connected_path, md_font_size * 1.1f);

//help.cpp
void md_format_cb(const ImGui::MarkdownFormatInfo& md_info, bool start)
{
	ImGui::defaultMarkdownFormatCallback(md_info, start);
}

void Help::markdown(const std::string& str_md)
{
	Font::md_config.linkCallback = NULL;
	Font::md_config.tooltipCallback = NULL;
	Font::md_config.imageCallback = NULL;
	Font::md_config.linkIcon = NULL;
	Font::md_config.headingFormats[0] = { Font::H1, true };
	Font::md_config.headingFormats[1] = { Font::H2, true };
	Font::md_config.headingFormats[2] = { Font::H3, false };
	Font::md_config.userData = NULL;
	Font::md_config.formatCallback = md_format_cb;
	ImGui::Markdown(str_md.c_str(), str_md.length(), Font::md_config); //segfaults
}

//call
const std::string str = u8R"(
		# H1
		## H2
		### H3
)";
Help::markdown(str);

Backend: opengl2 and glfw
DearImGui Version: 1.81 WIP

No or wrong text wrapping for links and headings.

There are two problems with the current code concerning text wrapping:

  • Headings are wrapped at the wrong position because TextRegion always uses the normal text font to compute the wrap position but the font of a heading is usually larger than that.
  • Links are not wrapped at all. Shouldn't the code use the RenderLine() function like the other text elements do?

Code organization / structure

@bkaradzic mentions in issue 4 that he would prefer a separate header for the external interface.

The way we use imgui_markdown.h in our project is we expose an external interface via our own string container, and the config isn't exposed. I'd thought people would likely use it that way, but I can see that for library projects they would like to expose a full external interface.

I think there are several alternatives here:

  1. Keep the code as it is.
  2. Stick to one header file, but add #ifdef to separate the external interface and declarations from implementation, so that you could create a header and source file via these.
  3. Split into two as per https://github.com/bkaradzic/bgfx/blob/master/3rdparty/dear-imgui/widgets/markdown.h
  4. Split into header and .cpp file.

Thoughts?

Will you consider add table?

Add basic table, so we can make item alignment in one row, like this

1 2 3
column 1 column2 long text 3
1 column2 long text

It's better if we can hide/show the title of the table, separator lines. thanx

imgui_markdown does not display the last character

Hi

As mentioned on twitter I started using imgui_markdown in glChAoS.P

Using imgui_markdown with my help strings I realized that it does not display the last character.

If the string is in form:

std::string markdownText = u8R"(
aaaaaP
)";

the problem does not seem to appear, because the last char is \n, but if I use:
std::string markdownText = u8R"(aaaaaP)";
or a more simple:
std::string markdownText = "aaaaP";
the P is not printed.

Thanks

no userdata for the callback?

I don't see an option to set a void* userdata pointer for the link callback. This forces use of globals some projects will not accept.

Link description text does not word wrap

The link description text (the one inside of [ ] ) is broken / split and does not word wrap. I have a single word for the description text and it gets split

See the attached screenshot where the single word "online" is split
image

Infinite loop when widget doesn't have enough horizontal space to fit a word.

There is bug here:

endPrevLine = pFont->CalcWordWrapPositionA( scale, text, text_end, widthLeft );

When widthLeft is too small to fit whole word endPrevLine doesn't advance and it causes infinite loop.

My workaround was:

if (text == endPrevLine) {
    endPrevLine++;
}

Other minor issues:

This:

HeadingFormat headingFormats[ NUMHEADINGS ] = { NULL, true, NULL, true, NULL, true };

Should be (fixes clang error):
HeadingFormat headingFormats[ NUMHEADINGS ] = { { NULL, true }, { NULL, true }, { NULL, true } };

Also I would suggest to create .h file that contains only definitions users should use. I did this inside bgfx:
https://github.com/bkaradzic/bgfx/blob/master/3rdparty/dear-imgui/widgets/markdown.h

Sorry for not creating PR...

math formula support

Thanks a lot ! imgui_markdown is exactly the library I am looking for.
I have one question that whether it can support math formula input as the markdown extension does? Or any solution/advice for doing this?

Feedback request: new formatting customisation technique

Branch: dev_format_callback

We'd like some feedback on our new MarkdownFormatCallback for customizable formatting. The way it works is you override DefaultMarkdownFormatCallback in your code to get features you require such as coloured text. See ExampleMarkdownFormatCallback for an example of how it works.

Introducing this method is the first step towards adding features such as bold or italics, and permits much more customisable formatting.

Thoughts?

Line returns forced on '\n' rather than " \n"

In most Markdown implementations a line return isn't added unless there are two empty spaces at the end of a line.
This lets you wrap your markdown file nicely in your editor whilst also allowing your end viewer to wrap it accordingly.

Any hope of adding bold and italic?

Markdown always has bold and italic formatting - which are very useful for emphasis. While I know official Dear Imgui has stated no interest in text formatting I thought maybe you would find interest in adding them.

C++11 support

imgui_markdown currently requires C++14 due to the use of aggregate initializers along with default member initializers. Adding C++11 constructors would break users' code in a way that would be difficult to workaround, and adding initializer list constructors is somewhat of a pain.

Question: do you need C++11 support and why?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.