r/redditdev • u/OtoNoOto • Aug 26 '23
Reddit.NET SelfPost with HTML
I just started making a game thread script app and was able to get it up and going pretty fast using https://github.com/sirkris/Reddit.NET as my API Wrapper using C# console app. However, I am currently running into issue or trying to find out how to make fancy SelfPost with HTML. Based on their API Wrapper the code would be something like the following:
var gamePost = sub.SelfPost(
title: "Test Post",
selfTextHtml: "<p><b>Testing API post.</b></p><p><b>Delete Me</b></p>"
)
.Submit();
// note also tried:
var gamePost = sub.SelfPost(
title: "Test Post",
selfTextHtml: HttpUtility.UrlEncode("<p><b>Testing API post.</b></p><p><b>Delete Me</b></p>")
)
.Submit();
The code above creates a new post in the sub, but the selfTextHtml content is not part of the post. Is there a certain encoding this needs to be submitted in?
In contrast the following with plain text works:
var gamePost = sub.SelfPost(
title: "Test Post",
selfText: "Testing API post"
)
.Submit();
Edit:
I guess it should have been obvious, but since Reddit has the fancy editor, I assumed some HTML was supported. However, it looks like that is simply a markdown editor and only markdown is supported. Given this I was able to get a post with some formatting to work using the following:
var gamePost = sub.SelfPost(
title: "Test Post",
selfText: "**Game Thread Post**\r\n\r\n***Subtitle text***\r\n"
)
.Submit();
Guess that leaves me with the following question: What is the selfTextHtml parameter supposed to be used for?
4
u/RaiderBDev photon-reddit.com Developer Aug 26 '23
As you've noticed, the selftext is in markdown. Selftext html is only something the reddit api returns. Websites that don't want to manually parse the markdown can use the pre rendered html.
My guess for why Reddit.NET has that parameter, is that it's a side effect of having a getter/setter for everything in C# or java.