Wingding issue in HTML Agility Pack - html-agility-pack

I am having a problem while using the HTML Agility Pack.
I have an html file. All I do is load that file using an HtmlDocument instance, and replace the urls of images in the document. Given below is the code used:
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
htmlDoc.Load(filePath);
HtmlNodeCollection images = htmlDoc.DocumentNode.SelectNodes("//img");
string source;
string imageName;
string newSource;
if (null != images && 0 < images.Count)
{
foreach (HtmlNode image in images)
{
source = image.Attributes["src"].Value;
imageName = Path.GetFileName(source);
newSource = imageUris[imageUris.IndexOf(imageName)];
if (null != newSource)
{
image.Attributes["src"].Value = newSource;
}
}
}
htmlDoc.Save(filePath);
The problem is that the Html document contains an empty check box and a check box with a 'x' created using the wingdigns font. After saving the file, the check box with 'x' in it gets changed to some weird characters like a left-pointing arrow, followed by 1 in a circle, followed by a clock and a number of A with ~ on top of it.
Similar thing happens with the empty check box.
Can someone please suggest some solution to preserve the check boxes?

Related

Image duplicates itself when using appendParagraph in Google Script

I wrote a script to add an image from my Google Drive and some custom text to a Google Doc. (I got the image insertion code from here).
The resulting document is created ok, but my image is added twice for some reason...
function myFunction(e) {
var doc = DocumentApp.create('fileTest');
var body = doc.getBody();
var matchedFiles = DriveApp.getFilesByName('logo.png');
if (matchedFiles.hasNext()) {
var image = matchedFiles.next().getBlob();
var positionedImage = body.getParagraphs()[0].addPositionedImage(image);
}
body.appendParagraph('Test line of text for testing');
doc.saveAndClose();
}
However, if I get rid of my appendParagraph code (body.appendParagraph(t1);) I only get one image (but obviously without the paragraph of text I want)
What's going on here? And how do I add both one picture and my paragraph of text?
I have not even the slightest clue as to why, but I found a way to make this work.
Switching the order of my code seemed to do the trick. I simply moved the image-insertion code to the end (i.e., after the appendParagraph code), and it worked fine. No duplicate image!
function myFunction(e) {
var doc = DocumentApp.create('fileTest');
var body = doc.getBody();
body.appendParagraph('Test line of text for testing');
var matchedFiles = DriveApp.getFilesByName('logo.png');
if (matchedFiles.hasNext()) {
var image = matchedFiles.next().getBlob();
var positionedImage = body.getParagraphs()[0].addPositionedImage(image);
}
doc.saveAndClose();
}

Why Does CKEditor Paste Image Work Here: http://sdk.ckeditor.com/samples/fileupload.html

What is so special about CKEditor on this page:
http://nightly.ckeditor.com/17-04-04-06-09/full/samples/
that you can effortlessly paste an image into the editor with a Chrome Browser? By effortlessly I mean:
Cut image to clipboard
Move cursor into editor.
Place cursor where you want image.
Ctrl-V
and you are done...just like in FF. This is the only sample CKEditor I have seen that allows such a convenient pasting.
I do not know what you mean by 'special', but if you're curious how it works...
How IT does it specifically would take too long to decipher as it's annoyingly obfuscated. Set a breakpoint at the first return of the word "paste" when you ctrl+f it (in ckeditor.js through dev console) and proceed to step through if you're brave. I got most of the way before I accepted it wasn't anything unique and not worth my time.
What's special about it? Nothing really... Trigger the event onPaste, get the images from the clipboard if they exist and read it .getAsFile, and then read said blob (output from .getAsFile) using .readAsDataURL and insert the result into an img elements src attribute.
Example:
<textarea id="pasteArea" placeholder="Paste Image Here"></textarea>
<img id="pastedImage"></img>
document.getElementById('pasteArea').onpaste = function(event) {
// use event.originalEvent.clipboard for newer chrome versions
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
var blob = null;
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image") === 0) {
blob = items[i].getAsFile();
}
}
if (blob !== null) {
var reader = new FileReader();
reader.onload = function(event) {
document.getElementById("pastedImage").src = event.target.result;
};
reader.readAsDataURL(blob);
}
}

link an image in tt_news

I'm using TYPO3 4.2.8 and tt_news 2.5.2. I tried the following snippet:
plugin.tt_news.displaySingle {
image {
# turn off default popup anchor
imageLinkWrap = 0
# add our link to the first URL in links field
stdWrap.typolink {
parameter = {current:1}
parameter {
setCurrent.field = links
setCurrent.listNum = 0
insertData = 1
}
}
}
}
Then I added an image to my news and also put a link into the link field (in the tab relations).
<LINK http://www.yourwesite.com/fileadmin/user_upload/downloads/broschure.pdf _blank>Download brochure</LINK>
But if I look at the news I don't have a link on the image. What do I have to change to get it work with my old version of tt_news?
Edit:
Now I tried it with gernericmarkers (idea from this topic). My TS looks like the following:
temp.img = COA
temp.img.5 = IMAGE
temp.img.5 < plugin.tt_news.displaySingle.image
temp.img.5 {
required = 1
wrap = |
file {
import = uploads/pics/
import.field = image
import.listNum = 0
}
titleText.field = title
altText.field = title
if.isTrue.field = links
imageLinkWrap.typolink.parameter.data = field:links
}
plugin.tt_news.genericmarkers.imagewithlink < temp.img
The marker is working but there is no content displayed in the news. What is wrong with my TS?
I don't know if this works in your old tt_news version but at least from version 3.0+ you can simply use the marker <!--###LINK_ITEM###--> around your image <!--###LINK_ITEM###--> inside your template to link anything you like to the detail page.
Your first snippet works, but you have to insert the link without the tags into the link field.
e.g.
http://www.yourwesite.com/fileadmin/user_upload/downloads/broschure.pdf _blank

Clickable Url in Twitter

i have implemented a simple twitter reader in my app. I am able to get the tweets of a
user. But, if there is a url in this tweet, i cant click on it, as its not detected as an URL.
Is there a possibility to implement this function, so that urls in the tweet are displayed
as clickable url, and then launch for example a webbrowser?
Thank you very much
I assume you are using a TextBlock to show the tweet text, correct? If so, change it to a RichTextBox and all you need to do is use Run for text and Hyperlink for the links!
Also, make sure you set the IsReadOnly property of the RichTextBox to true in order for it to work properly!
Next, parse the tweet text with a regular expression to find links, and use the Hiperlink class to create a clickable link on it, and Run on the remaining text!
Here's a sample function that will parse a tweet and build the content for a RichTextBox:
private Block ParseTweet(string tweetText)
{
var paragraph = new Paragraph();
var lastIndex = 0;
foreach (Match m in Regex.Matches(tweetText, #"(http(s)?://)?([\w-]+\.)+[\w-]+(/\S\w[\w- ;,./?%&=]\S*)?"))
{
if (m.Index > 0)
paragraph.Inlines.Add(tweetText.Substring(lastIndex, m.Index));
var hyperlink = new Hyperlink()
{
NavigateUri = new System.Uri(m.Value, System.UriKind.RelativeOrAbsolute),
TargetName = "_blank"
};
hyperlink.Inlines.Add(m.Value);
paragraph.Inlines.Add(hyperlink);
lastIndex = m.Index + m.Length;
}
if (lastIndex < tweetText.Length)
paragraph.Inlines.Add(tweetText.Substring(lastIndex));
return paragraph;
}
You should call this function like so:
var tweetText = #"Testing: http://twitter.com -> link for twitter";
MyRichTextBox.Blocks.Add(ParseTweet(tweetText));
I think it's not possible but but you can parse your text to find URL (with regex) and display a hyperlink below the text.
1) you search for URLs in the text with a regex
2) if a URL is found, you create a HyperlinkButton with this URL

newb: typo3 access uploaded images in typoscript

I'm trying to do something like in this Tutorial, a very basic gallery.
In the example of the Tut they load images from uploads/media/ like so
page.10.marks.PROJECTTHUMBNAIL = IMG_RESOURCE
page.10.marks.PROJECTTHUMBNAIL {
stdWrap.wrap = <img src="|" />
file {
import = uploads/media/
import.data = levelmedia: -1,slide
import.listNum = 0
}
}
but now I want to load pictures that have been uploaded in an image-cObject.
This is an embarrassing question but I've been trying to figure this out for two days and I can't seem to get it right -.- I'm sure there are lots of answers out there... I just don't know the magic words to put into google to FIND them T-T
I tried very basic stuff like just doing the same as above but with a different path, I rummaged through the TSRef of IMAGE and IMG_RESOURCE, tried fiddling with CONTENT, and tried to adapt the tt_content.image.20 = USER (?? O.o) description in the typoscript object-browser... but all to no avail, as I know so little what I'm doing -.-
Any nudge in the right direction would be greatly appreciated!
You have to load the content elements using the CONTENT cObject and set how the content shall be rendered. This will load Image content elements on the given page regardless of what column they are in:
page.10.marks.PROJECTTHUMBNAIL = CONTENT
page.10.marks.PROJECTTHUMBNAIL {
table = tt_content
select {
where = CType = 'image' AND image != ''
orderBy = sorting ASC
}
renderObj = IMAGE
renderObj {
file {
import = uploads/pics/
import.field = image
import.listNum = 0
}
}
}
NOTE: The renderObj is just my example and it renders only the first image of the Image element. You can set the rendering as you please, e.g. set the file to be GIFBUILDER which would allow you to resize the image. You can also tweak the select to load content elements with more refined conditions.

Resources