Getting strange character encoding in json output - json

Getting stuff like this in my JSON responses:
\u003Cp\u003EOur Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\u003C/p\u003E\n
I'm assuming CakePHP 3.3 is doing something here. Using standard json and xml route extensions. With set and serialize in my controllers. Nothing out of the ordinary that I can think of. Any idea how to change this to something that can be easily decoded by a client or just turn off the encoding all together?

There's nothing strange about this, that's simply unicode tag representations of the opening and closing angled brackets of the HTML tags in your content. This conversion is being applied when using the JSON_HEX_TAG option, which CakePHP does by default.
In fact, CakePHP currently uses
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT
by default. If you want to change this, use the _jsonOptions view variable option to define your own bitmask, or set it to false to disable the defaults, ie in your controller action do something like
$this->set('_jsonOptions', false);
See also
http://php.net/en/json_encode
http://php.net/manual/en/json.constants.php
Cookbook > Views > JSON and XML views > Creating JSON Views

Related

ARIA additional info to group content for screen reader (figure, div, aside etc.)

I'm trying to make text as accessible as possible. I'm wondering if there is a way to mark up structured elements that are visually distinguished from the main text.
Is there a way to put an invisible label on grouped content that is read by a screen reader?
exhample
grouped text thats surrounded by a red box (a div-Element) -the screen reader first reads "Red box"
a poem in a figure element -the screen reader first reads "Poem"
As I understand,
aria-label it only for interactive elements that replaces it (button)
aria-labeledby is connecting the grouped content with the visible headline
aria-describedby is connecting the grouped content with visible further information
I've read something about aria-description but it doesn't seem to be valid (oxygen doesn't allow it).
Or is the whole idea bad?
I think you might have a solution in resolving the following misunderstanding
aria-label it only for interactive elements that replaces it (button)
Also the region role and other structural roles (like table or form) need to carry a label:
Authors MUST give each element with role region a brief label…
And I believe the purpose of region is what you are looking for:
[…] containing content that is relevant to a specific, author-specified purpose and sufficiently important that users will likely want to be able to navigate to the section easily and to have it listed in a summary of the page.
region is the implicit role of a <section> element.
If you don’t judge it important enough to be included in the page summary, maybe the group role is more suitable.
Usually, when the reading cursor or focus enter a region or group, screen readers announce their accessible name. They will also announce when the grouping has been left.
<section aria-label="Red box" style="padding: .5em; border: 1px dashed red">
<p>This might get included in a page summary</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</section>
<div role="group" aria-label="Blue box" style="padding: .5em; border: 1px dashed blue">
<p>This will not get included in a page summary</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>

how to make line break in html without br [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
i have a lot of content and i am going to upload it to my website, and in website it will look like with no line breaks. and it will take a lot of time to add in content - <br>. Is there any other way to break lines?
Thank you!
I'll assume your original content has breaks caused by carriage returns or line feeds, but they're not rendered that way in your HTML.
To fix that, add CSS style pre-wrap:
div {
white-space: pre-wrap;
}
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
You can give width to paragraph tag or its parent tag. Please post your work in jsfiddle. So i can edit it and give it to you
Use CSS. For instance, if you have several paragraphs of text you can have a space between each one by just giving them a bottom margin as:
p { margin-bottom : 1em; }
That will give a complete blank line between each paragraph (or you could have 0.5em, say, to get half that amount of space, or any other measure. If you haven't used CSS before, now would be the time to learn, and it's pretty easy to learn the basics.
You can add CSS at the top of your HTML in the head section, for now (later learn how to put it into a separate file), doing:
<head>
....[other stuff here]
<style type="text/css">
p { margin-bottom : 1em; }
</style>
</head>
I imagine it would take even longer to wrap paragraphs in <p></p> than it would to add <br> between paragraphs. If I were going to take a huge amount of raw text and put it into content on a web page I would paste it into (or since I am a programmer write a program) a program that would make the conversion.
As I'm writing I'm thinking and wondering if you took your text and put it into MS Word and saved it as an HTML and made the format corrections could you get output from that that would work for your purposes?

Jekyll: Use an include from content

How can I use a short include in Jekyll's content (not in the template files) and have it rendered?
For example inside a page content or post I want to write something like this:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
{% include responsive_youtube.html video="nGeKSiCQkPw" %}
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
If I do it now Jekyll does not process the snippet it just posts the code. It works in template files but not as content. I'm using html with font matter code (and not markdown) as content.
Jekyll YouTube Embed Plugin can do it ! And you can find other plugins on the Jekyll plugins section.
Note that you cannot use this plugin with github pages.
This video is excellent !
{% youtube nGeKSiCQkPw %}
I definitely know that it's possible to use includes in the content, I made a site with Jekyll where I'm doing it exactly like this:
some text
{% include whatever.html %}
more text
The question is why it doesn't work for you.
You say you aren't using Markdown, but maybe the file still has the .md extension (even if you're using no Markdown inside, only HTML)?
If yes, Jekyll will treat it as Markdown.
I suspect that you indented the {% include... line like this:
some text
{% include whatever.html %}
more text
If yes, the Markdown parser will treat it as code.
Jekyll will still process the include and inject the HTML from the include file, but the HTML will not be rendered, but displayed as code because of the indentation.
If that doesn't help, you need to show us some actual source code.

Extracting all of html image tag, Rails

Afternoon all,
I am trying to write a script that will extract the first image from an article via its <img src=""/> tags. So if an article has:
<p>Lorem ipsum dolor sit amet, labore et dolore magna aliqua.<img src="example.jpg"/> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
I would like to extract the whole image tag, <img src="example.jpg"/>.
I found this regex which extracts just the location of the image:
content_to_extract_from[/img.*?src="(.*?)"/i,1]
produces, "example.jpg".
Does anyone know a regex that will capture the tags aswell?
Thanks in advance, Andy
Using regexes to parse markup is asking for trouble. You can probably write something that mostly works but which breaks on cases you didn't foresee. For example you can enclose attributes with single quotes instead of double quotes, which your regex won't handle
Much more reliable is to use a real parser, such as nokogiri
html = Nokogiri::HTML.fragment('<p>Lorem ipsum dolor sit amet, labore et dolore magna aliqua.<img src="example.jpg"/> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>')
html.css('img').collect(&:to_s) #=> ["<img src=\"example.jpg\">"]

HTML code in Rails YAML-fixtures

HI,
i have an "Article" model, that has HTML as it's content.
I have created some test data with YAML fixtures and faced following problem:
As i say "rake db:fixtures:load", following error appears:
ArgumentError: syntax error on line 22, col 0: <li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</li>
Fixtures fragment, it complains about, is following:
Article_1:
title: Test Article 1
content: |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<ul>
<li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</li>
<li>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</li>
</ul>
It seems, like the HTML code has something, that should not appear in YAML...
What is the proper way to write such a fixtures ?
I experienced a very similar error today when I needed to load a long JSON string in my fixture.
Unfortunately I wasn't able to fix it using Yaml but changing over to CSV did the trick. Perhaps that's something that you can try?
Instead of articles.yml you'll rename it to articles.csv. Keep in mind that the first line in the CSV file is a header record which needs to contain a comma separated list of field names after which the following lines can contain your data.
More details available over at http://ar.rubyonrails.org/classes/Fixtures.html which was a great help.
I just ran across something similar today embedding XML in a fixture. You should just be able to wrap your HTML in double quotes and it should work. Escape any double quotes in your HTML with an extra double quote.
You definitely need the | to handle multi-lines though because I was missing that at first so thanks for that tip.