How to render content of wordpress api? - json

I am creating a mobile app for a wordpress solution, while studying wordpress rest api, I have found a problem with the way the json schema is rendered;
while /wp-json/wp/v2/posts displays all posts but it is in this format
"title": {
"rendered": "testing rest api & #8220;tesint-restAP& #8221;"
},
How to extract the actual content from response.data.content because it came as html version with tags and such ???.

Tip for .NET Developers
When using http://restsharp.org/ in .NET to call the API, no parsing was required on the content.

First, get your json data with its html tags, then
var StrippedString = OriginalString.replace(/(<([^>]+)>)/ig,"");

Just use content of "rendered" as value for innterHTML property of element like div. It will work.
let htmlStr = `<p><em>“Anatomy of a Bear Market”</em> by Russell Napier is a <em>“must-read</em>” manuscript. Given current market dynamics, a review seems timely. As my colleague, Richard Rosso, CFP, previously penned:</p>`
let ele = document.getElementById('target');
ele.innerHTML = htmlStr;
<div id="target"></div>

Related

schema.org json-ld using coldfusion

I have not used json with coldfusion hence looking for some advice. I am trying to use coldfusion to get the schema.org json-ld work on a website. I have a query coming from a component which has the data that needs to go in the json. Can someone give me a gist of what needs to be done in order to spit out the json from the query in the below script tags on the page. Thanks in advance.
<script type="application/ld+json"></script>
I used this JSON-LD Schema Markup Generator to determine the fields and schema to use and then created a ColdFusion struct that matched it. For some elements (addresses, social media URLs, multiple locations), you'll need to create an array-of-structs.
There are many optional parameters you can add to each markup type, so it's difficult to program a one-size-fits-all solution. (I finally managed to write a custom tag that works specifically with our internal/custom CMS to auto-generate this for our client webpages.)
Here's a bare-bones ColdFusion sample for type "WebSite". (We've been adding inlining the JSON to the same webpage.)
<cfscript>
SchemaData = {
"#context" = "http://www.schema.org",
"#type" = "WebSite",
"name" = "My Website",
"alternateName" = "My Alternate Website Title (optional)",
"url" = "https://www.mywebsite.com/"
};
writeoutput('<script type="application/ld+json">#SchemaData#</script>');
</cfscript>

Converting mark down content to HTML in a Django-React app

I want to store blog content in my database, which I could then display in an HTML page, ideally by sending the content over an AJAX call.
After looking through the web I've read a few people suggesting storing the blog post as markdown which makes the most sense since it contains supports headers, paragraphs and code formatting, and mark down would be the easiest way to read/write the post.
However I'm not sure how to convert the markdown to an HTML page. I'm also not sure if I want to do that conversion client side (React frontend) or server side (Django Rest Framework backend).
What are some tools or methods to get this done given my stack?
I've done something similar, but with Angular - there are plenty of projects out there to help accomplish this. React-Markdown is one of them.
From their GitHub:
var React = require('react');
var ReactDOM = require('react-dom');
var ReactMarkdown = require('react-markdown');
var input = '# This is a header\n\nAnd this is a paragraph';
ReactDOM.render(
<ReactMarkdown source={input} />,
document.getElementById('container')
);

How to redirect to a webpage that accepts post requests?

I am working on a project where I need to scrap data in JSOUP and the show as HTML in my webpage and on clicking view more I am forwarding to the scrapped URL, issue is where GET url's are working fine but POST request for aspx are not working as it expects some __EVENTVALIDATION, etc,.. as input in form.
The webpage is kepler.sos.ca.gov, if you click on Corporation Name then enter ESCROW, then submit, some results will come up, which I am able to do in JSOUP, but unable to redirect using javascript:__doPostBack('ctl00$content_placeholder_body$SearchResults1$GridView_SearchResults_Corp','DetailCorp$0').
Please advice.
There is a answer over here : unable to get results from jsoup while giving post request
`Connection.Response response = Jsoup.connect(url)
.method(Connection.Method.GET)
.execute();
Document responseDocument = response.parse();
Map<String, String> loginCookies = response.cookies();
Element eventValidation = responseDocument.select("input[name=__EVENTVALIDATION]").first();
String validationKey = eventValidation.attr("value");
Element viewState = responseDocument.select("input[name=__VIEWSTATE]").first();
String viewStateKey = viewState.attr("value");
response = Jsoup.connect(url)
.cookies(loginCookies)
.data("__EVENTTARGET", "")
.data("__EVENTARGUMENT", "")
.data("__LASTFOCUS", "")
.data("__VIEWSTATE", viewStateKey)
.data("__VIEWSTATEENCRYPTED", "")
.data("__EVENTVALIDATION", validationKey)
.data("ctl00$content_placeholder_body$BusinessSearch1$TextBox_NameSearch", "aaa") // <- search
.data("ctl00$content_placeholder_body$BusinessSearch1$RadioButtonList_SearchType", "Corporation Name")
.data("ctl00$content_placeholder_body$BusinessSearch1$Button_Search", "Search")
.method(Connection.Method.POST)
.followRedirects(true)
.execute();
Document document = response.parse(); //search results
System.out.println(document);`
JSoup is not a browser. It does not interpret JavaScript and you can't fire a POST request through a JavaScript link.
JSoup is however quite capable doing POST requests. To use JSoup here, you need to figure out how the actual request is built by the JavaScript. You then can run the same algorithm coded in Java and create the link and do the POST request.
An easier way of achieving what you want is maybe a switch in technology. You can use selenium for example, which allows to "remote control" a real browser, which should have no problem running the JavaScript of that page.

How to retain the original html format when extracting content from web pages with boilerpipe?

I could extract the title and content (paragraphed) from the web pages on my Android application, but fail in fetching images sometimes.
However, I could not find a way to retain its html format parameters (e.g. bold, with a hyperlink, underline, or font size, etc..) in the extractor.
That is, if a sentence in the web page is equipped with bold, a hyperlink, or underline, how could I extract BOTH the sentence itself and its format parameters ?
I tried this page: An article both by the Web-API and APIs in local jar.
I would like to get the same result using local APIs as what Web-API did.
Could anyone share your experiences to this issue?
Much thanks,
James
Edit #1
Here are the codes:
signalUpdate(STATE.Start);
//
htmlDoc = HTMLFetcher.fetch(new URL(url));
//
doc = new BoilerpipeSAXInput(htmlDoc.toInputSource()).getTextDocument();
extraction.setTitle(doc.getTitle()); // obtaining title
ArticleExtractor.INSTANCE.process(doc); // obtaining content
SplitParagraphBlocksFilter.INSTANCE.process(doc);
contentBuilder.setLength(0);
for(TextBlock block : doc.getTextBlocks()) {
blockString = "<p>" + block.getText() + "</p>";
contentBuilder.append(blockString);
}
extraction.setContent(contentBuilder.toString());
// obtaining image
extractor = CommonExtractors.ARTICLE_EXTRACTOR;
ie = ImageExtractor.INSTANCE;
imgUrls = ie.process(new URL(url), extractor);
extraction.setImgUrls(imgUrls);
//
signalUpdate(STATE.Complete);
Actually, what I mean by "fail" is:
I could fetch images from some web sites. However, I could not get image in this article mentioned above.

Animating JSON data?

Dumb question time. I was trying to integrate my JSON data with a flipbook plugin, using a Mustache templating system. Needless to say, this wasn't working at all.
I'm a jQuery noobie, so is there any easy way to bind and animate the JSON data to/with a plugin (with or without the Mustache tags)??
From your question it is a bit hard to deduce what you want, but I feel you got already all the pieces together. First the example you have been linking to in a comment: https://github.com/blasten/turn.js/wiki/Making-pages-dynamically-with-Ajax
This fetches not yet loaded pages via Ajax, and the sample code assumes the Ajax call gets HTML back from the server, as can be seen in the code snippet from there (after adding a missing '}':
$.ajax({url: "app?method=get-page-content&page="+page})
.done(function(data) {
element.html(data);
});
Here the done function processes the data it got back from the server by straight injecting it into the element, which is expected to contain the current page.
I assume next that you do have a server side method, but that method returns JSON instead. Let me assume for the moment that it returns the following structure:
{ "title" : "the title of page N",
"text" : "here is some text for the page N." }
The next thing is to render this JSON into into html in the done funktion, before inserting the result into the page. Looking at the short tutorial on the README.md this might look like:
$.ajax({url: "app?method=get-page-content&page="+page})
.done(function(data) {
var pageHtml = Mustache.render("<h2>{{title}}</h2><p>{{text}}</p>", data);
element.html(pageHtml);
});
If the server returns the proper data you should now see a
<h2>the title of page N</h2><p>here is some text for the page N.</p>
appear on the page.