Is it possible to assign a multiline text value in a semantic mediawiki subobject ?
I'd like to do something like
{{#subobject:
|multiline=line1
a list on line 2:
*list item 1 on line3
*list item 2 on line4
|foo=bar
}}
setting multiline texts for ordinary objects works with
[[multiline1::<br>
list
*item 1
*item 2]]
I wonder if it's possible for subobjects as I would like to attach multiline notes for to do subobjects
Your example is:
{{#subobject:
|multiline=line1
a list on line 2:
*list item 1 on line3
*list item 2 on line4
|foo=bar
}}
This will give an error message that the multi line content "line1..." can not be used as a page title.
This is because the default property type is page. You need to change the property type via special page [[Property:multiline]]
See http://semantic-mediawiki.org/wiki/Help:List_of_datatypes e.g. http://semantic-mediawiki.org/wiki/Property:SomeProperty has the type text, which is declared via
[[Has type::Text]]
So you might want to do the same for your multiline property.
The following query shows the wanted result:
{{#ask:
[[foo::+]]
|?multiline
|?foo
}}
Related
Thanks to this answer I've created a template which mix a visual representation and populates a semantic one.
I've used the template in a page but the last part doesn't work and returns the following message.
Property "" (as page type) with input value "psicologia|governo|politica|lavoro|+sep=|" contains invalid characters or is incomplete and therefore can cause unexpected results during a query or annotation process.
The template:
[{{{url}}} {{{title}}}] - {{{categories}}}
{{#subobject:
|url = {{{url}}}
|title = {{{title}}}
|#category={{{categories}}}
}}
The desired behaviour:
{{#subobject:
|url = https://www.instagram.com/p/CXeE2j-NT6s/
|title = Bullismo: proposta una legge in Francia per punirlo penalmente. Si rischia anche il carcere
|#category=bullismo|violenza|leggi|punizioni|+sep=|
}}
You cannot use | as a separator, it will not recognize it as a separator, try a comma, a hyphen or something that you generally don't use in Mediawiki coding
I have an html that looks like this:
<div class='textContainer'>
<div class='textLabel'> </div>
<div class='text'>
"First Line of text"
"Second Line of text"
"Third line of text"
</div>
</div>
I can easily create a locator to find the node that contains the text, but I need to run an assertion specifically on the first and third lines of text... So, I would need specific locators for those.
Like
//div[#class='text']/text[1]
//div[#class='text']/text[3]
Is that even possible to do?
Any help will be appreciated.
Thanks!
You can do that with XPath 2 or 3, e.g. in the browser or Node.js with Saxon-JS 2 you have XPath 3.1 support:
const lines = SaxonJS.XPath.evaluate(`//div[#class = 'text']/tokenize(., '\n')[normalize-space()]!normalize-space()`, document, { xpathDefaultNamespace : 'http://www.w3.org/1999/xhtml' });
console.log(lines);
console.log(lines[0]);
<script src="https://www.saxonica.com/saxon-js/documentation/SaxonJS/SaxonJS2.rt.js"></script>
<div class='textContainer'>
<div class='textLabel'> </div>
<div class='text'>
"First Line of text"
"Second Line of text"
"Third line of text"
</div>
</div>
Note that in any version of XPath or the DOM the normalized tree has a single text node but in XPath 2 or later you can split or tokenize the string of a text node into sequences of strings and process each string in the sequence. The Saxon-JS 2 API to JavaScript nicely gives you that XPath 3.1 string sequence back as a string array in JavaScript.
In terms of the XPath 2 or 3 data model the path expression //div[#class = 'text']/tokenize(., '\n')[normalize-space()]!normalize-space() gives a sequence of string you can positionally index as usually in XPath with integer numbers so let $lines := //div[#class = 'text']/tokenize(., '\n')[normalize-space()]!normalize-space() return $lines[2] returns the second item/second string in the sequence of strings (of normalized text lines of the text node).
I have the following code:
...
<tr ngFor= "let i = index">
<myCustomElement myName="{{'nameEdit'+i}}">
<button
<--This is where I get the "Got interpolation ({{}}) where expression was expected" error-->
(click)="myFunction(requestForm.controls.'nameEdit'{{i}}.value)">
</button>
</myCustomElement>
</tr>
...
My goal is pass to myFunction the value of nameEdit for each element (so this will be nameEdit1, nameEdit2, nameEdit3 and so on. My existing code results to an Got interpolation ({{}}) where expression was expected error.
What's the proper way to pass my value to myFunction?
(click)="myFunction(requestForm.controls['nameEdit' + i].value") should do the trick
Since double quotes for event directives (...) are interpolated, the {{ ... }} is unnecessary. You will need to also use the javascript object identifier [...] with the dynamic text.
Lastly, this will obviously return error if the controls doesn't have a key with the name you're trying to parse. It would be best practice to have myFunction(...) manage this case.
Working stackblitz example that outputs the values: https://stackblitz.com/edit/angular-whq8ll-od64hx?file=app/slider-overview-example.html
I'm trying to send Some Markdown text to a rest api. Just now I figure it out that break lines are not accepted in json.
Example. How to send this to my api:
An h1 header
============
Paragraphs are separated by a blank line.
2nd paragraph. *Italic*, **bold**, and `monospace`. Itemized lists
look like:
* this one
* that one
* the other one
Note that --- not considering the asterisk --- the actual text
content starts at 4-columns in.
> Block quotes are
> written like so.
>
> They can span multiple paragraphs,
> if you like.
Use 3 dashes for an em-dash. Use 2 dashes for ranges (ex., "it's all
in chapters 12--14"). Three dots ... will be converted to an ellipsis.
Unicode is supported. ☺
as
{
"body" : " (the markdown) ",
}
As you're trying to send it to a REST API endpoint, I'll assume you're searching for ways to do it using Javascript (since you didn't specify what tech you were using).
Rule of thumb: except if your goal is to re-build a JSON builder, use the ones already existing.
And, guess what, Javascript implements its JSON tools ! (see documentation here)
As it's shown in the documentation, you can use the JSON.stringify function to simply convert an object, like a string to a json-compliant encoded string, that can later be decoded on the server side.
This example illustrates how to do so:
var arr = {
text: "This is some text"
};
var json_string = JSON.stringify(arr);
// Result is:
// "{"text":"This is some text"}"
// Now the json_string contains a json-compliant encoded string.
You also can decode JSON client-side with javascript using the other JSON.parse() method (see documentation):
var json_string = '{"text":"This is some text"}';
var arr = JSON.parse(json_string);
// Now the arr contains an array containing the value
// "This is some text" accessible with the key "text"
If that doesn't answer your question, please edit it to make it more precise, especially on what tech you're using. I'll edit this answer accordingly
You need to replace the line-endings with \n and then pass it in your body key.
Also, make sure you escape double-quotes (") by \" else your body will end there.
# An h1 header\n============\n\nParagraphs are separated by a blank line.\n\n2nd paragraph. *Italic*, **bold**, and `monospace`. Itemized lists\nlook like:\n\n * this one\n * that one\n * the other one\n\nNote that --- not considering the asterisk --- the actual text\ncontent starts at 4-columns in.\n\n> Block quotes are\n> written like so.\n>\n> They can span multiple paragraphs,\n> if you like.\n\nUse 3 dashes for an em-dash. Use 2 dashes for ranges (ex., \"it's all\nin chapters 12--14\"). Three dots ... will be converted to an ellipsis.\nUnicode is supported.
Summary
Using Django 1.8, I'm trying to make a Function Based View that renders an html page that allows me to update the contents of the object. I'm able to get this to work by using the form.as_p as shown in the documentation here, but I can't get these values inside an html <input> as the value.
Issue
The issue is that only the first word appears and the rest of the text is cut off (e.g. for a html input tag, the value of 'Hello World Will' gets turned into 'Hello')
model.py
class Questions(model.Model):
title = models.CharField(max_length=512, null=False, blank=False)
forms.py
class QuestionsForm(forms.ModelForm):
class Meta:
model = Questions
fields = ('title', )
views.py
def advice_update(request, pk)
question_results = Questions.object.get(id=pk)
advice_form = QuestionsForm(request.POST or None, instance=question_results)
...
return render(request, 'advice/advice_update.html', {'advice_form': advice_form, 'question_results': question_results,})
advice_update.html
<form method='POST' action=''>{% csrf_token %}
# METHOD 1 - This code works and renders the form with paragraphs enclosed
# but I want more control
{{ advice_form.as_p }}
# METHOD 2 - When I try to get the value by itself, it works too
{{ advice_form.instance.title }} # E.g. 'Hello World'
{{ question_results.title }} # E.g. 'Hello World'
# METHOD 3 - When I try to put the text inside a 'value' tag in an 'input',
# the text gets cut off and only the first word appears in the input
# When I look at the console, I see the rest of the text in there.
<input id="id_title" type="text" name="title" class="form-control" value={{ question_results.title }}>
I tried a few things like adding autoescape and safe tags, but when I use METHOD 3, the value inside the tag of advice.html cuts off when there's a space (e.g. 'Hello World' turns into 'Hello').
First, you don't need to set null=False, blank=False on your title field as those are there by default.
It looks like the main issue you're having is adding the Bootstrap css class to the form element, which you can accomplish a couple of different ways. Also note that your value attribute is missing quotes around it.
The first way is to add the appropriate classing to the widget from the Python side of the form:
class QuestionsForm(forms.ModelForm):
class Meta:
model = Questions
fields = ('title', )
def __init__(self, *args, **kwargs):
super(QuestionsForm, self).__init__(*args, **kwargs)
self.fields['title'].widget.attrs['class'] = 'form-control'
However, this gets really tedious when you're dealing with a lot of form fields. So, I use django-widget-tweaks to instead add these at the template level:
{{ form.title|add_class:"form-control" }}
which I find a lot easier to deal with. This way you don't have to render the field by hand. Also be sure to handle the case if there's no matching question in your view:
question = get_object_or_404(Question, id=pk)