I have a question.
How can I extract an url from an rss-feed?
The string which I need to extract is something like this:
><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="screen2" src="http://hereisthelink/screen2.png" alt="screen2" width="261" height="434" border="0" />
This is on the rss feed of my self hostet wordpress-blog, within the <content:encoded> section.
I want to fetch the first Image of an entry to get it together with the title (this works) in my ListBox.
However I tried many things to achieve this, but nothing works.
I am working with the Syndication.dll of Silverlight 3 to extract the feed items.
At the moment I am standing really in front of a wall for this to solve.
I am open to any suggestions.
You can use HTML Agility pack http://htmlagilitypack.codeplex.com/ There's a version for Windows Phone (HAPPhone in the trunk). After getting a Document from the content of the post you can get the first img element child of them.
var firstimage = document.DocumentNode.Descendants("img").FirstOrDefault();
Something like this should work for you:
var document = XDocument.Parse(html);
var items = new List<Item>();
var channel = (XContainer) document.Root.FirstNode;
foreach (XElement item in channel.Nodes())
{
try
{
var item = new Item();
var nodes = item.Nodes().ToArray();
foreach (XElement keyValue in nodes)
{
var value = keyValue.Value.Trim('\r', '\t', '\n', ' ').ToLower();
switch (keyValue.Name.LocalName)
{
case "title": item.Title = value; break;
case "content:encoded": item.Content = value; break;
// TODO: add more fields
}
}
var match = Regex.Match(item.Content, "<img(.*?) src=\"(.*?)\"[^>]*>");
item.FirstImageUrl = match.Groups[2].Value;
}
catch
{
// TODO: handle exception
}
}
return items;
You only have to finish the switch statement and create the Item class.
Related
I try to convert from html to pdf using jsPDF.
I could not get the pdf as the original html.
ordered list and unordered list bullet points are missing in the pdf file.
ordered-list-in-html
ordered-list-in-pdf
unordered-list-in-html
unordered-list-in-pdf
function BlazorDownloadFile(filename, text) {
let parser = new DOMParser();
let doc = parser.parseFromString(text, "text/html");
console.log(doc.body);
const element = doc.body;
var opt = {
margin: 1,
filename: filename,
html2canvas: { scale: 2 },
jsPDF: { unit: "cm", format: "a4", orientation: "portrait" },
};
// Choose the element that our invoice is rendered in.
html2pdf().set(opt).from(element).save();
}
Please help me to fix this issue.
Here is a workaround for bullet points in scss you can use to overcome this issue:
ul li {
list-style-type: none;
&:before {
content: '• ';
margin-left: -1em;
}
}
I want to use google spreadsheet with android. I Tried example program. I created new datasheet. I used example script code. I tried mit2 app program. This program is example program. I also used postman.
Postman show me error.
Postman error page.Postman connection error status 200 OK.
Postman error message is:
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico">
<title>ERROR</title>
<style type="text/css" nonce="B6c+P2HTW+vClzlpE+anwg">body {background-color: #fff; margin: 0; padding: 0;}.errorMessage {font-family: Arial,sans-serif; font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style>
</head>
<body style="margin:20px">
<div>
<img alt="Google Apps Script" src="//ssl.gstatic.com/docs/script/images/logo.png">
</div>
<div style="text-align:center;font-family:monospace;margin:50px auto 0;max-width:600px">TypeError: Cannot read property 'getSheets' of null (line: 15, file: "denandroid")</div>
</body>
</html>
script code is :
function doGet(e) {
return ManageSheet(e);
}
function doPost(e) {
return ManageSheet(e);
}
function ManageSheet(e) {
//READ ALL RECORDS
if ( e.parameter.func == "ReadAll") {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0]; // Postman problem line.
var rg = sh.getDataRange().getValues();
var outString = '';
for(var row=0 ; row<rg.length ; ++row){
outString += rg[row].join(',') + '\n';
}
return ContentService.createTextOutput(outString).setMimeType(ContentService.MimeType.TEXT);
}
//DELETE SINGLE RECORD
else if (e.parameter.func == "Delete") {
var record = e.parameter.id;
var ss = SpreadsheetApp.getActive();
//var ss = SpreadsheetApp.openById(e.parameter.ID);
var sh = ss.getSheets()[0];
//var sh = ss.getSheetByName(e.parameter.SH);
sh.deleteRow(parseInt(record) + 1); //makes the correct row to delete (because of header row)
return ContentService.createTextOutput("Success, requested action completed");
}
}
postman says problem line in script code line 15. ( var sh = ss.getSheets()[0]; // Postman problem line)
Also I am using turkish language on google sheets. english name Sheet1 turkish language Sayfa1
I tried both names.
but unsuccess.
I am using this line for the connection spreadsheet.
https://script.google.com/macros/s/AKfycbyTt9oaz10WuKh0822hBncRoJZAw-D4hcGMwJwdy95l8H_mXfE/exec?ID=18NFZD7vZ-JySbbV7jiZMBpiBsoLJ4IQge9Wk9cL6Z4c&SH=Sheet1&func=ReadAll
Please help.
Thanks
Problem solved. The problem is the sharing problem. When sharing, it should be (Anyone, even anonymous). google always wanted me to sign in. When sharing (script code file) must be, In the 1st window, (me and gmail address) should be selected. (Anyone, even anonymous) should be selected in the 2nd window. sheet name not problem
I want to switch pages using neon-animated-pages
So my code is simple:
<dom-module id="auth-view">
<template>
<style>
</style>
<neon-animated-pages class="neon-container" selected="[[selected]]">
<login-page></login-page>
<pwd-reset-page></pwd-reset-page>
</neon-animated-pages>
</template>
</dom-module>
And in dart code:
#property
int selected = 0;
StreamSubscription _clickSubscription;
attached() {
_clickSubscription = this.on['showPwdReset'].listen((e) {
e = convertToDart(e);
// Read things from `e`.
print("Got show Event!");
selected = 1;
});
}
So, I catch the event - I can see that in console. But page does not change.
I still can change it manually with adding selected in shadow-dom.
What's the problem?
The pageitems should be wrapped with <neon-animatable>
like:
<neon-animatable><login-page></login-page></neon-animatable>
<neon-animatable><pwd-reset-page></pwd-reset-page></neon-animatable>
For more info https://www.webcomponents.org/element/PolymerElements/neon-animation/neon-animatable
I wish to detect what media query is active - I'm using Bootjack, so hence I am using the default breakpoints
I expected to be able to use getComputedStyle() to get hold of the value of the 'content' property in the example below - but I don't seem to get the syntax correct. I can happily get the value of an element - say the font-famly on the body, but not pseudo-elements...
Here's what I am doing:
Given this css..
/* tablets */
#media(min-width:768px){
body::after {
content: 'tablet';
display: none;
}
}
#media(min-width:992px){
body::after {
content: 'desktop';
display: none;
}
}
#media(min-width:1200px){
body::after {
content: 'large-screen';
display: none;
}
}
I have this in my dart file:
String activeMediaQuery = document.body.getComputedStyle('::after').getPropertyValue('content');
but activeMediaQuery is always empty.
I've tried ('after') and (':after') and anything else weird and wonderful but to no avail.
String activeMediaQuery = document.body.getComputedStyle().getPropertyValue('font-family');
sets the variable activeMediaQuery to the value of the font-family that I am using (not much use to me though!)
What should I be doing?
You can also subscribe to MediaQuery change events
for more details see https://github.com/bwu-dart/polymer_elements/blob/master/lib/polymer_media_query/polymer_media_query.dart
There is a bug in Dart and the workaround uses dart-js-interop.
This is the code from the polymer-media-query element. I don't know if the comments not suppored in Dart yet are still valid. It's a few months since I tried it.
Here is an example page that shows how to use the element.
https://github.com/bwu-dart/polymer_elements/blob/master/example/polymer_media_query.html
var _mqHandler;
var _mq;
init() {
this._mqHandler = queryHandler;
mqueryChanged(null);
if (_mq != null) {
if(context['matchMedia'] != null) {
_mq.callMethod('removeListener', [_mqHandler]);
}
// TODO not supported in Dart yet (#84)
//this._mq.removeListener(this._mqHandler);
}
if (mquery == null || mquery.isEmpty) {
return;
}
if(context['matchMedia'] != null) {
_mq = context.callMethod('matchMedia', ['(${mquery})']);
_mq.callMethod('addListener', [_mqHandler]);
queryHandler(this._mq);
}
// TODO not supported in Dart yet (#84)
// Listener hast to be as MediaQueryListListener but this is and abstract
// class and therefor it's not possible to create a listner
// _mq = window.matchMedia(q);
// _mq.addListener(queryHandler);
// queryHandler(this._mq);
}
void queryHandler(mq) {
queryMatches = mq['matches'];
//fire('polymer-mediachange', detail: mq);
}
This worked for me with the CSS you provided in your question but only when the window was wider than 768 px. You might miss a rule with max-width: 768px
import 'dart:html' as dom;
void main () {
dom.window.onResize.listen((e) {
var gcs = dom.document.body.getComputedStyle('::after');
print(gcs.content);
});
}
I'm trying to use class names to change the color of a link after it has been selected, so that It will remain the new color, but only until another link is selected, and then it will change back.
I'm using this code that was posted by Martin Kool in this question:
<html>
<head>
<script>
document.onclick = function(evt) {
var el = window.event? event.srcElement : evt.target;
if (el && el.className == "unselected") {
el.className = "selected";
var siblings = el.parentNode.childNodes;
for (var i = 0, l = siblings.length; i < l; i++) {
var sib = siblings[i];
if (sib != el && sib.className == "selected")
sib.className = "unselected";
}
}
}
</script>
<style>
.selected { background: #f00; }
</style>
</head>
<body>
One
Two
Three
</body>
It works fine until I try to out the links in a table. Why is this? Be easy, I'm a beginner.
There is no error, the links are changing to the "selected" class, but when another link is selected, the old links are keeping the "selected" class instead of changing to "unselected". Basically, as far as I can tell, it's functioning like a vlink attribute, which is not what I'm going for.
And yes, the links are all in different cells, how would you suggest I change the code so that it works correctly?
OK, actually, I spoke too soon.
document.onclick = function(evt)
{
var el = window.event? event.srcElement : evt.target;
if (el && el.className == 'unselected')
{
var links = document.getElementsByTagName('a');
for (var i = links.length - 1; i >= 0; i--)
{
if (links[i].className == 'selected')
links[i].className = 'unselected';
}
el.className = 'selected';
}
return false;
}
This code you gave me works great, visually, it does exactly what I want it to do. However, It makes my links stop working... They change color, but dont link to anything, and then when I remove the script, they work fine. What am I doing wrong/what do I have to change to make this work?
Also, I want to do the same thing somewhere else in my website, where the links are all in one <div> tag, separated by <p> tags. How can I make this work?
You're looping through the siblings. If the links are in separate <td>'s then they're no longer siblings.
You can loop through all the links like this:
document.onclick = function(evt)
{
var el = window.event? event.srcElement : evt.target;
if (el && el.className == 'unselected')
{
var links = document.getElementsByTagName('a');
for (var i = links.length - 1; i >= 0; i--)
{
if (links[i].className == 'selected')
links[i].className = 'unselected';
}
el.className = 'selected';
}
return false;
}
I've also added a return false; at the end of the function to stop you going to '#'
Is there an error or is there just nothing happening? A good first step if you are a javascript beginner is to use a tool like Firebug so you see detailed error messages, and you can add in console.log statements to see what's going on while you run your code.
By ‘in tables’ do you mean putting each link in its own cell? Because that would make this line:
var siblings = el.parentNode.childNodes;
fail to select other links outside of the cell. You'd have to find another way to signal which element is the link container.