-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added nolinks flag to skip links during rendering #80
base: master
Are you sure you want to change the base?
Conversation
fuzzing/snudown-validator.c
Outdated
@@ -129,6 +136,14 @@ void init_wiki_renderer() { | |||
sundown[RENDERER_WIKI].toc_state = &wiki_toc_state; | |||
} | |||
|
|||
void init_default_renderer_without_links(PyObject *module) { | |||
PyModule_AddIntConstant(module, "RENDERER_USERTEXT_WITHOUTLINKS", RENDERER_USERTEXT_WITHOUTLINKS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version doesn't have a python module to initialize.
💇 |
snudown.c
Outdated
@@ -10,6 +10,7 @@ | |||
enum snudown_renderer_mode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this repeated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repeated where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly same code is in fuzzing/snudown-validator.c
I don't understand how fuzzer/validator works in this code base, yet, but that seems like a DRY violation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely agree. But, at least it doesn't register modules, also there are some minor differences that may affect something. I asked Peter about it. His response: "snudown-validator is the snudown.c with a main() function added, so it can be run as a standalone program for fuzz-testing."
I thought about rewriting this part to use validator.c but because I'm not sure how to test it, I decided to leave it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we just have a .h
file that we include from fuzz and main ?
Can you also describe the business logic of this as well as the reasoning behind this change in the OP? |
I've introduced a feature that if subreddit is specific list and someone mentioned user or subreddit in comments for post in this subreddit, users won't receive messages that someone mentioned their name. |
This is just the render part, right? Where is the business logic code that decides which subs to use this new renderer for? |
💇 |
snudown.h
Outdated
@@ -0,0 +1,118 @@ | |||
/* snudown.h - header for snudown */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice. this works just as before for fuzzing as well as using from python?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems so. I was able to run all tests using python setup.py test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet.
AFAIK putting function definitions in .h
is not best practice because it gets inlined everywhere in exec, but it should not matter here. Probably someone who knows more about this code base should also weigh in on this decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I remember, definition is ok, implementations is not the best practice. I checked other h
files and they almost all have function definitions. But agree, if we have some one who has good experience in C, we can ask him\her
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this works for the python module form, it's not well structured and will cause maintenance problems in a few years.
Please put all of the implementations in a separate file. Maybe renderers.c
?
The new files will need to be mentioned in fuzzing/CMakeLists.txt
to allow snudown-validator to be fuzz tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @pwildani's approach. I really should have put all the shared rendering logic into a shared renderers.c
when I first wrote the fuzzing code 😬 .
Also, I don't believe the fuzzer is invoked when calling python setup test
. The fuzzing process has a number of extra dependencies (AFL, CMake, the custom Google gumbo bits...) that aren't needed for functional tests. It also doesn't really fit into what people would normally expect python setup.py test
to do (you need to run it for multiple days to get trustworthy results.)
I need to update the docs on how to run the fuzzing though, feel free to ping me on Slack about getting it working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you guys explain maintenance problems caused by including definition in .h?
Is it because it would be difficult to use different implementation of the functions in case its needed (Such as slightly different implementation in fuzzer code, or somewhere else?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really a maintenance problem per se, it's just generally considered bad form to have the function implementation itself in the .h
instead of the .c
. Having the function definition in the .h
is OK and generally what you want.
Any function implementation longer than 1-2 lines should be in a .c
it only needs to be compiled to a single .o
and the implementation won't need to be recompiled for every object with a .c
file with #include "snudown.h"
.
Also, if you put the implementation in the .h
rather than the .c
, any change to the function implementation will trigger a recompile of any objects that reference snudown.h
. If the implementation is somewhere like renderers.c
, then a change to the implementation will only require a recompile of that specific object file and a re-link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include
is dumb and copy pastes code. If you put implementations in headers, they get copy pasted into every module that includes it which means redefinitions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for clarification, guys.
I haven't reviewed the current version yet, but the goal is to allow disabling user and subreddit mentions on a per-subreddit basis as a penalty for abusing the feature. Disabling all automatic links might be reasonable fallout. Butler's notifications are handled in a separate PR. |
snudown.h
Outdated
/* snudown.h - header for snudown */ | ||
|
||
/* | ||
* Copyright (c) 2017, Evgenii Timofeev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: We haven't added copyright headers to any of the files added in our fork of Sundown, but copyright should be assigned to Reddit if we do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
If the intent is to disable all linking from posts under this new rendering mode we should add testcases to ensure the other forms of links are rendered as plaintext as well:
|
snudown.c
Outdated
#include "autolink.h" | ||
#include "snudown.h" | ||
|
||
#define SNUDOWN_VERSION "1.4.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we should bump this a minor version too, fancy new features!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
💅 Some questions RE how regular links should behave |
💇 |
src/markdown.c
Outdated
md->active_char['<'] = MD_CHAR_LANGLE; | ||
md->active_char['\\'] = MD_CHAR_ESCAPE; | ||
md->active_char['&'] = MD_CHAR_ENTITITY; | ||
|
||
if (extensions & MKDEXT_AUTOLINK) { | ||
if (!(extensions & MKDEXT_NO_EMAIL_AUTOLINK)) | ||
md->active_char['@'] = MD_CHAR_AUTOLINK_EMAIL; | ||
if (md->cb.image || md->cb.link) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change confuses me.
[text](http://url)
isn't an automatic link, it's an explicit one the user wrote out, so why would the MKDEXT_AUTOLINK flag affect how that syntax is rendered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. We also don't want to skip by the link structure entirely, we just want to not render the link. Outputting [foo](/bar)
verbatim probably isn't the way to go either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it confuses, but I tried to avoid situations when user is mentioned my direct, without investing much effort. I'll revert this part, so link will be rendered as expected
@@ -0,0 +1,98 @@ | |||
#include "markdown.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔕 Exactly right file structure
src/renderers.h
Outdated
struct snudown_renderopt options; | ||
}; | ||
|
||
static char* html_element_whitelist[] = { "tr", "th", "td", "table", "tbody", "thead", "tfoot", "caption", NULL }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. A static
declaration in a header makes a copy of the thing in every compilation unit in which it is included.
Declare the variable as extern
here, and define it in the renderers.c, so every reference uses the one compiled into renderers.o
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll move it to c, also don't think that someone outside renderer should know about it
1 thing about links and why I've moved if (md->cb.image || md->cb.link) under if (extensions & MKDEXT_AUTOLINK): |
💇 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
🐟 |
1 similar comment
🐟 |
OMG, this is still open?! |
Woah. close this plz@ |
👓 @pwildani @lan17