Markdown citations in octopress - wiki

I'm using markdown a lot and would like to have a few pages that mimic the behavior of wiki reference.
For example:
Blah blah blah <ref>{{Some Reference}}</ref>
I'll be adding a lot of references throughout a few pages and am not sure how to accomplish this behavior in markdown. All the resources I've found require a lot of work to keep track of them, you have to order them yourself, both at the bottom and top of the page, as opposed to Wiki markup which can automatically build the list at the bottom of a page with a simple {reflist}. Something similar to the TOC. Is there nothing like this in Markdown?
How could I extend RedCarpet or another processor to manage ref links throughout the page and build a list?

I don't think there's an easy way out of the box, but you can use a jekyll extensions such as:
https://github.com/archome/jekyll-citation
https://github.com/inukshuk/jekyll-scholar
Looks something like:
#book{ruby,
title = {The Ruby Programming Language},
author = {Flanagan, David and Matsumoto, Yukihiro},
year = {2008},
publisher = {O'Reilly Media}
}
Not sure how easy it would be to use for simple web references such as your example, but it would work.

Related

Customising the Quick Info Section in the Content Editor of Sitecore

Is it possible to customise the quick info section in the content editor to show additional information about the item?
Thanks
I think this would be quite tricky. If you look at Sitecore.Shell.Applications.ContentManager.Editor (in Sitecore.Client.dll), you'll see there is a RenderQuickInfo method. The HTML gets pieced together manually and is added to an EditorFormatter object as a literal control. All the classes involved are tightly integrated in to the application - there's no easily identifiable customisation point.
There are some pipelines associated with the rendering of the Content Editor,
renderContentEditor
getContentEditorFields
getContentEditorSkin
But I don't think these will provide an easy way in.
In general, I always think that if Sitecore haven't made part of the application easily customizable, then they probably did it on purpose.
One option could be a more js approach. The whole of the content editor is in the dom, albeit rather nested. It's slightly different but highlights the concept (http://blog.boro2g.co.uk/ever-edited-sitecore-web-db-mistake/).
I'd suggest if you use the example below in anger you make the xpath better - this was simply stolen from chrome dev tools.
As an example: with the following script pasted into the content manager.aspx file you can access some of the elements:
<script type="text/javascript">
window.onload=function(){
var text = getElementByXpath('//*[#id="EditorPanel"]/table/tbody/tr/td/table/tbody/tr[2]/td[1]');
if (text) {
text.innerText = "hi";
} else {
}
};
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
</script>
Which then allows you to update text (see screenshot):
quickinfo says hi

Django: DRY Internal links in TextFields

I have a site with a bunch of 'Projects' which often refer to each other in their descriptions (stored in a TextField).
Rather than hard-coding the links between projects in their descriptions, I'd like to keep things DRY by referring to them using some sort of token, for example, in the description field:
Blabla text describing this project, this project was inspired by
{{ project "ProjectB"}} and lead to the development of {{ project "ProjectC" }}.
Which is then processed and turned in to:
Blabla text describing this project, this project was inspired by
ProjectB and lead to the development
of ProjectC.
To be clear: the description is free text which can contain none to many references to other items as hyperlinks at various points in the text. In a CMS this effect is usually achieved through some way to link to items by node/object ID - so that if the link changes, the reference can still be followed.
I've considered:
Evaluating the text field as a Template and using the 'url' templatetag in descriptions. Seems like the easiest solution but that templatetag isn't particularly friendly for content editors and evaluating each description through the entire Template renderer seems a bit cumbersome.
Implementing a templatetag which just re-implements a basic faux-templating system to just parse out a nice simple tag just for this purpose.
Extending the TextField to pre-process the description before it's saved to the database.
Has anyone done anything similar? What would you suggest?
I just answered a similar question on SO, and it seems like it might solve your problem as well (if by chance you're still looking for an answer three years later).
I wrote a template filter to parse the custom internal link format in the Textfield before display. I'm using Markdown to parse my textfields, so I made the links return in Markdown format, but they could easily be written as HTML instead.
Check out my answer here.
Update: I posted a revised version on djangosnippets.org that resolves internal links inside a markdown-formatted link, as well as on their own.
if I got your problem, you should use a custom template processor to pass a dictionary to your templates:
in settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"myapp.myprocessor.foo",
)
in myapp/myprocessor.py:
from django import template
def foo(request):
ProjectA = get_Project_from_database
t = template.Template(ProjectA.html)
c = template.Context({'name': ProjectA.name})
rendered_ProjectA = t.render(c)
return { 'rendered_ProjectA': rendered_ProjectA }
or if you don't wanna use Django template system you can use regular expressions (import re)

Customizing Containable Content in Orchard CMS

I am currently trying to understand a bit more about how Orchard handles Lists of Custom Content Types and I have run into a bit of an issue.
I created a Content Type named Story, which has the following parts:
Body
Common
Containable
Route
I created a list that holds these items, and all I am attempting to do is style them in such a way:
Story Title
Story Description (Basically a truncated version of the body?)
However, I cannot seem to figure out how to do the following:
Get the Title to actually appear (Currently all that appears is the body and a more link)
Remove the "more" link (and change this to be the actual Title)
I have looked into changing the Placement.info, and have looked all over in an attempt to find where the "more" link is added in each of the items. Any help would be greatly appreciated.
I finally managed to figure it out - Thanks to the Designer Tools Module, which made it very simple to go look into what was going on behind the scenes during Page Generation.
Basically - all that was necessary to accomplish this was to make some minor changes to the Parts.Common.Body.Summary.cshtml file. (found via ../Core/Common/Views/)
Which initially resembles the following:
#{
[~.ContentItem] contentItem = Model.ContentPart.ContentItem;
string bodyHtml = Model.Html.ToString();
var body = new HtmlString(Html.Excerpt(bodyHtml, 200).ToString()
.Replace(Environment.NewLine,"</p>"+Environment.NewLine+"<p>"));
}
<p>#body #Html.ItemDisplayLink(T("more").ToString(), contentItem)</p>
however by making a few changes (by using the Designer Tools) I change it into the following:
#{
[~.ContentItem] contentItem = Model.ContentPart.ContentItem;
string bodyHtml = Model.Html.ToString();
string title = Model.ContentPart.ContentItem.RoutePart.Title;
string summary = Html.Excerpt(bodyHtml, 100) + "...";
}
<div class='story'>
<p>
#Html.ItemDisplayLink(title, contentItem)
</p>
<summary>
#summary
</summary>
</div>
Although it could easily be shortened a bit - It does make the styling quite a big easier to handle. Anyways - I hope this helps :)
Alternately you can use the placement.info file in your theme assign different fields to your Summary and Detail views. It's much simplier.
http://orchardproject.net/docs/Understanding-placement-info.ashx
But, I used the same method you did till I discovered the .info file as well. It works and gives you a good understanding of how the system works, but the placement.info file seems easier.
Also, you probably don't want to be editing the view files in Core. I think your meant to override views in your theme directory.

Cleansing string / input in Coldfusion 9

I have been working with Coldfusion 9 lately (background in PHP primarily) and I am scratching my head trying to figure out how to 'clean/sanitize' input / string that is user submitted.
I want to make it HTMLSAFE, eliminate any javascript, or SQL query injection, the usual.
I am hoping I've overlooked some kind of function that already comes with CF9.
Can someone point me in the proper direction?
Well, for SQL injection, you want to use CFQUERYPARAM.
As for sanitizing the input for XSS and the like, you can use the ScriptProtect attribute in CFAPPLICATION, though I've heard that doesn't work flawlessly. You could look at Portcullis or similar 3rd-party CFCs for better script protection if you prefer.
This an addition to Kyle's suggestions not an alternative answer, but the comments panel is a bit rubbish for links.
Take a look a the ColdFusion string functions. You've got HTMLCodeFormat, HTMLEditFormat, JSStringFormat and URLEncodedFormat. All of which can help you with working with content posted from a form.
You can also try to use the regex functions to remove HTML tags, but its never a precise science. This ColdFusion based regex/html question should help there a bit.
You can also try to protect yourself from bots and known spammers using something like cfformprotect, which integrates Project Honeypot and Akismet protection amongst other tools into your forms.
You've got several options:
"Global Script Protection" Administrator setting, which applies a regular expression against post and get (i.e. FORM and URL) variables to strip out <script/>, <img/> and several other tags
Use isValid() to validate variables' data types (see my in depth answer on this one).
<cfqueryparam/>, which serves to create SQL bind parameters and validate the datatype passed to it.
That noted, if you are really trying to sanitize HTML, use Java, which ColdFusion can access natively. In particular use the OWASP AntiSamy Project, which takes an HTML fragment and whitelists what values can be part of it. This is the same approach that sites like SO and slashdot.org use to protect submissions and is a more secure approach to accepting markup content.
Sanitation of strings in coldfusion and in quite any language is very important and depends on what you want to do with the string. most mitigations are for
saving content to database (e.g. <cfqueryparam ...>)
using content to show on next page (e.g. put url-parameter in link or show url-parameter in text)
saving files and using upload filenames and content
There is always a risk if you follow the idea to prevent and reduce a string by allow basically everything in the first step and then sanitize malicious code "away" by deleting or replacing characters (blacklist approach).
The better solution is to replace strings with rereplace(...) agains regular expressions that explicitly allow only the characters needed for the scenario you use it as an easy solution, whenever this is possible. use cases are inputs for numbers, lists, email-addresses, urls, names, zip, cities, etc.
For example if you want to ask for a email-address, you could use
<cfif reFindNoCase("^[A-Z0-9._%+-]+#[A-Z0-9.-]+\.(?:[A-Z]{5})$", stringtosanitize)>...ok, clean...<cfelse>...not ok...</cfif>
(or an own regex).
For HTML-Imput or CSS-Imput I would also recommend OWASP Java HTML Sanitizer Project.

How to define parent and subpages in Trac?

I know the Confluence wiki pretty well, and I like much the natural hierarchy of pages you get there. I have to use now a Trac wiki (which is not that bad, same root as MoinMoin), and am searching the feature here. What I want to reach:
Edit the page "MyPage" and enter there the link to a page you want to be a subpage, eg. MySubPage.
The link should be similar to /MySubPage or [/MySubPage]. The character "/" denotes that the resulting page should be a subpage of the current one.
Follow the link, create the new page with some content.
You should now see, that "MySubPage" is a subpage of "MyPage". You could reach the subpage from anywhere by the link MyPage/MySubPage.
The MoinMoin wiki has that feature at least from version 1.5.x, and I have used that regularily. Is there something similar in Trac? Do I have to install then a plugin?
Thank you a lot
Markus
Well, not the best thing to answer the own question, but just something I found out.
* SubpageFirst
* SubpageSecond
* SubpageThird
* SubpageFourth
leads to (of course) four pages, but when you have a look at them in Title Index, you will see:
* Subpage
* First
* Second
* Third
* Fourth
Not what I have searched for, but comes near.
The only way I have found to do something like this is to specify the full path to the page. For your example this would be [[MyPage/MySubPage]]. You then get a hierarchy in TitleIndex, but it leaves much to be desired in terms of presenting a Parent/Child relationship.
I think, as retracile mentioned, that MyPage/MySubPage does not create a true hierarchy, but rather just a page containing a forward slash in the name, and in TitleIndex the pages are presented such that they appear to be in a hierarchy (but often do not display the way you would like; as I mentioned it leaves much to be desired).
Parent-child wiki pages aren't directly modeled in Trac. Essentially, "/" is allowed as part of a wiki page name.
You should be able to create a macro that does something like what you want; essentially:
[[sub(MySubPage)]]