I'm making a detail page about certain items.
This detail page can contain large blocks of text, and the customer would like to only show the first 100 letters and then put a " ... more " at the end.
When the user clicks this " ... more " the rest of the text can be shown.
Biggest problem: the text is currently is a CMS and has large varieties. Some is pure text, some have html elements in them ...
I tried to cut off the text and put them in spans. Then i could show/hide these spans as i please. The issue here is that there can be a starting element of a certain tag in the first span and the closing element can be in the second span. This causes the DOM hierarchyto be faulty and the result is never pretty.
Does anyone know a ( other ) way to achieve this or a library i can use ?
To be able to extract "readable" characters you need to get the content into a plain text format (get rid of the mark-up).
Since the content is stored in a cms it is likely that the content is structured to be well formed - thus xhtml.
If that is the case you can treat the content as XML. Get the root node and get the innertext property there-of. Then you will have plain text - no tags - and can easily cut it after the first 100 characters or whatever the requirement is.
Hopefully the content doesn't contain js/css!
Edit:
It seems that the markup must be retained.
Try the following xsl to transform and truncate the content:
https://gist.github.com/allen/65817
Related
I want to check in c# if an html document is "visibly empty". Checking InnerHtml is not enough, because the HTML could contain an image or an empty table.
Are there any efficent ways to check a HTML document if there is anything, that translate to something that is not a whitespace?
The complicated way i'm thinking of is removing every html/body/p/br Tag, whitespaces and nbsp items, and checking if anything is left
Need some HTML code for Escape characters that accepts and do its functionality in a TextBlock.
For Example:
for \n
My requirement is, I have a XML file which holds a field named Memo and it need to hold some text like in the below image
For CCJS, i need a tab to make it center. like wise the rest of text to be aligned.
XML tag:
memo="\tCCJS
\t==========
If the "CCJS" field is customized on the General Occurrence screen, then the same custamization should be made to the "CCJS Status" field on the conclusion block."
Above given is just for an example, I have more text like these so i need some set of HTML code to have all these Text accepted in xml and Textblock
I have gone through Here.. Still i dont found code for Tab. if i would get a full list of these codes, it would be helpful..
Thanks.
I've always just used the Line Feed character (which will work in xaml and is html encoded, it's also already included your example)
Dec. =
Hex. =
As example;
<TextBlock Text="Line One
Line Two"/>
Hope this helps.
PS - for your tabs, just get your spacing correct and utilize Preserve Whitespace / xml:space="preserve"
I'm generating an MS Word document from user data. The data is placed in a container which is serialized to XML, and the resulting XML is converted to OpenXML using XSLT. There are a few minor changes done programmatically in C# to generate the Word document, as they can't be done with XSLT.
There is a user requirement that an item be placed completely on one page without any associated data being split onto another page. Sometimes one item will fill up an entire page, and sometimes I can fit three or four items on one page (I need to insert a separator (horizontal rule) between items that fit on the same page.)
Is there a way to determine whether or not one item or OpenXML paragraph will fit entirely on the "current" page? This can be either via C# or XSLT, and I can work something out.
Unfortunately, the only way this can be reliably done is to actually render the output, including all of the font sizes, bolding, kerning and all that. Which means you have to do the pagination in Word, and then save it back to the OpenXML.
I have successfully generated a word document file using open XML, but I have got too many blank pages,
how can i remove them ?
This depends on how those blank pages are represented in the Open XML; you may want to post a sample document to demonstrate exactly how your blank pages are represented.
But let's take the case of a Word document in which a user has inserted extra page breaks (by hitting ctrl-enter in Word), resulting in blank pages. These page breaks will be represented in the XML as:
<w:br w:type="page"/>
The page will still have plenty of tags in it for spacing, fonts, etc.; and the page may display header and footers, too. But let's define a blank page as one which has no new paragraph text. In Open XML, new text is displayed with a w:t tag.
So, in order to remove blank pages created by extra page breaks with no text in between, we can run the following regular expression on the XML document, replacing with blank (""):
<w:br w:type="page"/>(.(?!<w:t>))*(?=<w:br w:type="page"/>)
This regex will search for a series of two or more page breaks with no new text in between, removing all but the last one.
(Note that this won't take care of blank pages at the end of the document, which is a bit trickier. Additionally, if you'd like to account for pages with images, textboxes, etc., the regex will have to be expanded to include the relevant items).
We are developing C#.Net(4.0) Windows Form Based Application with the use of Open Xml Sdk(2.0) for manipulating MS-WORD Files.Now i want to get the all the paragraphs in particular page.The user prompted for getting particular page no of the word file to get the all the paragraphs inside the user selected page number. How i do it?
Taking a quick look at the underlying XML it doesn't look like there is an attribute on the paragraph element that will tell you which page it will appear on. The best suggestion I can give you is to have some placeholder text at the top and bottom of each page. Then search for the a certain instance of the placeholder text based on which page the user specifies. Once you have a starting point you could retrieve all paragraphs between the two placeholder paragraph elements.
For example, if a user enters in page two, you would search for the third instance of a paragraph that contains this placeholder text and then retrieve all paragraphs until you reach the next instance of the placeholder text. I know this isn't ideal, but its one workaround I could think of that might be feasible.