How to do a READme style markup in reactjs? - reactjs

I am pretty new to reactjs. I was assigned with a task which consists of generating the "privacy policy" of the website. The layout of the page kinda looks like a readme of github.
1.header
***some points in block letters***
A. subsection
B. another subsection
- item
- item
C. a)item
b)item
I could easily do with simple header and paragraph tags with some styling. But we've included translations in the page, so all of the texts are coming from a json file incorporated with export default defineMessages() from messages.js.
Is there any way there is some kind of markup or template which will make my work easier?
n.b. Being a novice to reactjs, I tried my best to make the question as much simple as I could. Any help will be appreciated!

Related

How do i let a user insert a link in an input field with normal text?

I am using react.js
I'm trying to build a blog page.
there is a texterea tag to write a blog for the user.
now I want to add the function that allows users to add words that are linked.
so that when i show the text from that input words that are linked are clickable
enter image description here
like the blue words in wiki in the image above.
pardon my mistakes (1st question in StackOverflow)
I know about dangerouslysetinnerhtml. but not sure if it's the right way to do so. because then users can modify the code inside (i think). so what is the safe and right way to do so
Reading your case Markdown seems best option as it also supports links insertion. For rendering user entered markdown you may use library like React Markdown. For writing markdown textarea is fine as long as you write markdown syntax properly but you may want to consider libraries like React textarea markdown editor to make things easier.

Link to an anchor on another episerver page

Is there an elegant way of linking to anchors in some other page in EpiServer that will keep the links relevant - even after the anchor names change? I am 95% sure there is no standard way of doing this, so thoughts on custom implementations are welcome.
There are existing plugins, but ...
I found this plugin to EpiServer that will basically scrape all the anchors from the page you are interested in, and present them in a drop-down in the TinyMCE wysiwyg editor. But as the anchors have no unique attributes that makes it possible to follow them through changes, these anchor links will rot in time, as changing <a name="Meeting"></a> to <a name="Appointment"></a> will make previously created links invalid.
Thoughts on how this could work
I am not super-familiar with how to easily work with ContentTypes in EpiServer, but I would assume it should be possible to create some kind of property, HtmlAnchors, that would be a collection of strings that could be employed on a page. These would be regarded as constants in practice, and I am quite certain that there is a way in EpiServer of checking if a page property is in use, so if one of these strings (HtmlAnchor) are referenced on some other page, it would be impossible to delete it without removing the references. That would make anchor links always be consistent and referable.
Possible workflow: An editor opens the page property view and presses the + sign on the "HtmlAnchors" property. Adds the string "detailed-overview". A front-ender working with code would then add something like that to the page template:
<h4 name=#Model.Anchors("detailed-overview")>Overview</h4>, and in referring pages use the (as of yet non-existing) url helper #Url.PageLinkWithAnchor(Model.PageLink, "detailed-overview") to create a link to that anchor.
If using a wysiwyg editor then it could use IAnchorPage#Anchors() to list the existing anchors and IAnchorPage#AddAnchor() to add an anchor.
Of course, I see how what I sketched out above seems to rest on a shaky foundation, as it uses simple strings ... which might not really add much else than overhead.

blogger - filtering archive list widget by labels

I have made a blogger site for a friend. She wanted 2 blogs on the one site which I managed to achieve using search and labels.
http://thewishingtreeandotherdreams.blogspot.co.nz/search/label/moon
http://thewishingtreeandotherdreams.blogspot.co.nz/search/label/blog
Now what I want to do is also filter the archive widget based on the above labels.
I know I will have to have a second archive widget so one shows only "moon" labeled posts and the other only shows "blog" labeled posts
My programming knowledge however is VERY limited. Has anyone else already done this. Do you have code you could share with me?
Here's a script with similar functionality but not include nesting by dates. Only copy and edit the next code into new HTML/JavaScript widget.
<script src="http://cloud.github.com/downloads/jhwilson/Create-a-Blogger-archive-page/Make-Blogger-Archive-Page.js"></script>
<script src="http://NAME_OF_YOUR_BLOG.blogspot.com/feeds/posts/default/-/LABEL_NAME?max-results=500&alt=json-in-script&callback=LoadTheArchive"></script>
If adds some CSS could be look better.

Sublime Text 2: Different language highlighting based on context? (a la Webstorm)

I was watching some videos on Egghead.io about AngularJS. The creator of the videos uses Webstorm (and, I believe, works for them). One feature I noticed is that he can set different syntax highlighting within different scopes or quotation marks. So, in code like the following (from an AngularJS directive)
return {
template: '<div>something</div>',
// ^^^ these guys ^^^
}
...he can get the inside of the quotation marks to highlight as HTML.
I use Sublime Text 2, and am fairly wedded to it. Is there an existing feature/plugin for Sublime that could handle a case like this? If not, is something like this technically possible using the Sublime Text 2 API?
I don't think it's built in, but it's certainly possible. I've been doing some work with graphviz and wanted to do something similar. Labels can be generated with html like syntax. Anyways, I played around with the .tmLanguage file and added a new pattern to match the context where html like entries were valid (I look for label = <). The patterns I used for the captures aren't that good, but it works for fine for me. This give me the following, which I think is similar to what you are looking for.
I don't know anything about AngularJS, so I can't help you with anything specific to that, but it is certainly possible. Note that in the image below, the last <table></table> are just to show that highlighting doesn't occur there.
Edit:
Forgot to include this in the original post, but here is my updated tmLangauage file. That first pattern is what I added(link). I used PlistJsonConverter to go from JSON to plist, then saved the file as .tmLanguage. Hope this helps.
#skuroda is right, I implemented #skuroda's code with an additional plugin to easily edit HTML within an AngularJS directive JS file. The result is HTML syntax highlighting within a directive JS file and additional functionality to remove string related delimiters while editing templates.... Sublime AngularJS HTML Template Plugin

How to add a custom field into template.php using Zen sub theme

First time poster here, I'm a designer not skilled at all with php and I have a small issue I don't seem to be able to solve. I'm making a site in drupal 7 using a sub theme on zen.
Btw this is a great CMS, even though people say it's really more a developers CMS. I have no trouble to do what I need using views, rules, display suite etc. So a big thank you for all the developers out there making this such a good CMS. But for this apparently simple problem... no module will help me (I think) and I'm kinda stuck.
So here it is: I'd like to add a subtitle next to the title in all my pages.
So what I did was to add a custom field into the content type basic page (machine name: field_sub_title) which is a simple text field.
I uncommented the following line in my template.php
function mytheme_preprocess_page(&$variables, $hook) {
$variables['sub_title'] = t('field_sub_title');
}
Now my question is how do I load the content of my custom field into that variable?
I know i need to change the second part, but I don't have a clue as into what I need to change this.
Displaying the variable into the the page.tpl.php is something I know about so I only need help with the first part.
{EDIT}
Ok I found how to do this :)
I was looking for a solution in the wrong place. I don't need to change any thing in the template.php file.
Just needed to add this bit of code into my page.tpl.php:
<?php
print $node->field_sub_title['und'][0]['value'];
?>
So I'm posting this here for other Drupal newbies struggling with this....
Your solution may work for now, but there may be a more Drupal-y way to handle a problem like this. If you haven't noticed any problems yet, you may find one or more of the following issues down the road:
Someone who doesn't know php or Drupal theming may need to change the way this works.
If you're like me, you may forget where exactly in code this was implemented.
You may see superfluous markup and/or errors on nodes (content) that do not have this sub-title field (ie. event content not having a sub-title field while basic pages and news articles do).
When you add a field to a content type, it will automatically appear anytime content in that content type is displayed. You should be able to add the sub-title field for your page, event or whatever else you need and have it automatically appear in the markup.
You can 'manage display' of a content type to drag and drop the order for fields to appear. You could take it a step further by using a module like Display Suite to add formatting or layout per-content type.
If you feel like this isn't good enough and the markup for the subtitle must be at the same level as the page title (which is rare), at least add an if statement to make your code check to see if the variable is present before trying to print it. I'd also add a new variable and comments for code readability.
<?php
$subtitle = $node->field_sub_title['und'][0]['value'];
if($subtitle){
print $subtitle;
}
?>
Consider using field_get_items or field_view_value, or at least use the LANGUAGE_NONE constant instead of 'und'
See https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_items/7 and https://api.drupal.org/api/drupal/modules!field!field.module/function/field_view_value/7
This has the added benefit of reducing the number of potential security holes you create.

Resources