Only display one paragraph of text - perl

You can set what the Facebook Share preview says. I would like it to be the first paragraph of my movable type entry. The people who make entries sometimes use
<p>
tags or they use the rich editor which puts in two
<br /><br />
tags to separate paragraphs.
Is there a way I can have movable type detect when the first paragraph end and only display the first paragraph? I would like to add that to my entry template so it will add some information to my head.

EntryBody has a lot of attributes to help format the output of the tag. You can use those to change the content so it shows up correctly in HTML, JavaScript, PHP, XML or other forms of output.
If you understand how to use regular expressions, you can use that and an additional language, say PHP, to break the body up into an array and only output the first paragraph or element of the array.
The simplest thing, though, I would think, would be to do something like
<mt:EntryBody words=100>
That will cut off the entry body after the first 100 words. You could also require users to upload an excerpt with the entry and use the entry excerpt for Facebook, instead.

Related

Superscript within code block in Github Markdown

The <sup></sup> tag is used for superscripts. Creating a code block is done with backticks. The issue I have is when I try to create a superscript within a code block, it prints out the <sup></sup> tag instead of formatting the text between the tag.
How do I have superscript text formatted correctly when it's between backticks?
Post solution edit
Desired output:
A2 instead of A<sup>2</sup>
This is not possible unless you use raw HTML.
The rules specifically state:
With a code span, ampersands and angle brackets are encoded as HTML entities automatically, which makes it easy to include example HTML tags.
In other words, it is not possible to use HTML to format text in a code span. In fact, a code span is plain, unformatted text. Having any of that text appear as a superscript would mean it is not plain, unformatted text. Thus, this is not possible by design.
However, the rules also state:
Markdown is not a replacement for HTML, or even close to it. Its
syntax is very small, corresponding only to a very small subset of
HTML tags. The idea is not to create a syntax that makes it easier
to insert HTML tags. In my opinion, HTML tags are already easy to
insert. The idea for Markdown is to make it easy to read, write, and
edit prose. HTML is a publishing format; Markdown is a writing
format. Thus, Markdown's formatting syntax only addresses issues that
can be conveyed in plain text.
For any markup that is not covered by Markdown's syntax, you simply
use HTML itself. ...
So, if you really need some text in a code span to be in superscript, then use raw HTML for the entire span (be sure to escape things manually as required):
<code>A code span with <sup>superscript</sup> text and escaped characters: "<&>".</code>
Which renders as:
A code span with superscript text and escaped characters: "<&>".
This is expected behaviour:
Markdown wraps a code block in both <pre> and <code> tags.
You can use Unicode superscript and subscript characters within code blocks:
class SomeClass¹ {
}
Inputting these characters will depend on your operating system and configuration. I like to use compose key sequences on my Linux machines. As a last resort you should be able to copy and paste them from something like the Wikipedia page mentioned above.
¹Some interesting footnote, e.g. referencing MDN on <pre> and <code> tags.
If you're luck, the characters you want to superscript (or subscript) may have dedicated codepoints in Unicode. These will work inside codeblocks, as demonstrated in your question, where you include A² in backticks. Eg:
Water (chemical formula H₂O) is transparent, tasteless and odourless.
I've listed out the super and subscript Unicode characters in this Gist. You should be able to copy and paste any you need from there.

MS Word - fomat a Content Control with bullet points

I'm working with Content Controls in MS Word 2010. I add text to the Content Controls using Java. Some of the text contains several sentences and I would like to see each sentence appear as a bullet point. I've managed to define a bullet point style in MS Word. However, I don't know how to make each sentence appear as a bullet point (now the entire text appears as just one bullet point). What is the best way of going about this? I'm considering using VBA but am not sure how to add a VBA macro to a Content Control.
In Word, bullet points are implemented via list numbering.
For list numbering, you need paragraphs (you set the numPr on the pPr).
For a content control to contain paragraphs, you need a block level content control.
So, you need a block level rich text content control, then put your content in it, one paragraph per sentence, formatted using your list numbering (either directly applying the numPr, or a style which uses that numPr).

GitHub MarkDown: Are Macros and Variables possible?

I've been learning github markdown, I had a question about variables and macros.
is it possible to define a variable or macro to prevent repeated printing of a block of text?
The use case is that I have a table producing a big grid of hyperlinks - the links look like the below.
http://www.a-big-long-big-big-long-hyperlink/more-long-stuff?id=1234
it would be nice if I could do something like the below once:
$link=http://www.a-big-long-big-big-long-hyperlink/more-long-stuff?id
and then in each cell in the table, I can say something like
$link=1234
Some other cell
$link=2345
the idea being that:
The table (which has ~10 columns and ~10 rows) is a bit easier to see on a normal screen, at the moment with the prefix to the links being so long, it looks really ugly as the links wrap to the next line
If I want to change the root link, I can change it in one place (yes, I know I could do search and replace in an editor!)
Cheers.
Below are a few ways to write Reference-Links
[I'm an inline-style link](https://www.somewebsite.com)
[I'm an inline-style link with title](https://www.somewebsite.com "somewebsite's Homepage")
[I'm a reference-style link][Arbitrary case-insensitive reference text]
[I'm a relative reference to a repository file](../blob/master/LICENSE)
[You can use numbers for reference-style link definitions][1]
Or leave it empty and use the [link text itself]
Some text to show that the reference links can follow later.
[arbitrary case-insensitive reference text]: https://www.somewebsite.org
[1]: http://somewebsite.org
[link text itself]: http://www.somewebsite.com
You can use a feature of Markdown called "Reference-style links".
[link text][id] or just [link text] if link-text is unique and consist only of letters, numbers, spaces and punctuation. They are not case sensitive.
then somewhere in the document you define what id is:
[id]: http://example.com/whatever
See
https://github.com/biserkov/markdown-playground/blob/master/README.md and
https://raw.githubusercontent.com/biserkov/markdown-playground/master/README.md
GitHub Markdown (for .md files) has variables through capture:
{% capture nameOfVariableToCapture %}any markdown here...{% endcapture %}
{{ nameOfVariableToCapture }} -- that prints the content of the variable
or from {% assign variableName = "text etc." %}.
As a test, I created https://github.com/SeLite/SeLite.github.io/blob/master/MarkdownTest.md. You can see its content at http://selite.github.io/MarkdownTest (ignore the header and footer, that comes from a framework).

How can I identify an OpenXml Paragraph as one I programmatically inserted?

I am programmatically adding an OpenXML paragraph to a Word Document and I need to be able to identify that paragraph as mine later on. Any ideas on how to do this? I have tried inserting an XML comment and extended attributes but when you save the document in word it removes all unknown xml. It doesn't matter if it is an attribute in the paragraph or the run, or an element before the paragraph, just some way I can identify it later on. Also, I do not want this identifier visible in the word document.
Examples of what I could use:
<paragraph id="myParagraph"></paragraph>
<otherelement>myparagraph</otherelement>
<paragraph></paragraph>
Any help would be AWESOME because my head it hurting from the brick wall I have been running into.
Thanks!
Give the paragraph a w:rsidR attribute and assign a unique value to it; if there is no value present when word saves the document it will randomly assign it's own 8-digit hexadecimal value anyway. (The value is not limited to 8 digits or hexadecimal characters. Word will not modify existing RSIDs.)
That being said -- make sure to keep RSID values unique and do NOT modify existing RSID attributes -- they are the unique ID for that paragraph, and if the document splits into multiple versions and a user tries to merge them back together those RSIDs are used to determine what paragraphs have changed.
(Also note that runs have RSIDs as well.)
If the user modifies the paragraph, the RSID of that paragraph may change.
The alternate option is to use Custom XML: http://msdn.microsoft.com/en-us/library/bb608618.aspx
Use stylename in paragraph properties.
or try this one
http://msdn.microsoft.com/en-us/library/office/hh674468.aspx
Hope this helps.

with tinymce, how to convert an html tag into a different format

I want to convert an HTML tag that tinymce returns into a different format.
e.g.
The italics tag I want to convert to #i#
Is that possible with the editor itself?
During postback I strip all html tags, so I need it in a different safer format.
Add an onsubmit call to your form and use a simple javascript function to string replace the html tags you want to keep.
A more constructive method that might achieve what you want is to use the built in 'Valid elements' feature of tinymce. You can specify exactly which HTML tags you want to keep and it will strip out anything else. Plus it might be able to save you the step of stripping out the HTML yourself.
e.g.
valid_elements : "i,b,u",
http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/valid_elements