I have to select only the characters contained from > to the last dot (not the first dot).
I tried this pattern
^>[a-zA-Z]+$
but something doesn't work. Can I get some help? Thank you.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
I made an example using javascript to have a working demo but since I had to use a strategy where the commonly used . (dot) should match also line breaks, in this case I was forced to use [\s\S] instead.
the regex ^>[\s\S]+\.\n expects to find a > at the beginning of the line followed by any character until the last dot found followed by a new line.
This demo feeds the regex match with the full text and returns just the middle part as you were expecting:
const subject = `
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.`;
var re = /^>[\s\S]+\.\n/im;
var match = re.exec(subject);
if (match != null) {
result = match[0];
} else {
result = "";
}
console.log(result);
C# .Net Solution
(>[\s\S]*\.)
Or if you don't want to capture the > and . then you can use a positive look behind and positive look ahead.
To match all characters and whitespace in between we can use [\s\S]* This works by default in .Net due to aggressive matching
(?<=>)([\s\S]*)(?=\.)
Try this fiddle: https://dotnetfiddle.net/3ukM0X
public static void Main()
{
string content = #"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
"">""Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.";
var regex = new System.Text.RegularExpressions.Regex(#"(?<=>)([\s\S]*)(?=\.)");
Console.WriteLine(regex.Match(content));
}
Returns:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat
If there can not be any > chars in the paragraph, only at the start, then you can use:
^>[^>]*\.
^ Start of string
> Match literally
[^>]* Match optional chars other than >
\. backtrack to match the last occurrence of the dot
See a regex demo
If you want to allow the > char in the paragraph (but not at the start as that denotes the start of the paragraph) you can match all lines after it that do not start with <
^>.*(?:\r?\n(?!>).*)*\.
See another regex demo
Related
Got a situation where currently notes logged by users are saved to a single file, with a timestamp, userid, and the note.
I would like to extract each instance of a note, and put it into a spreadsheet.
For the usernames, I have \([\w']+?, [\w']+?[ \w]{0,2}\) : (http://regexr.com/3fjf5)
The dates will be similarly trivial.
The part with which I'm struggling is grabbing the text following the timestamp and username. I tried using a negative lookahead for timestamp/username, but this will not work for the final line in the log, as it is not followed by a timestamp/username combo.
I have a solutions that involve appending a delimiter, or making two passes with regex, but I'm curious whether this can be done in a single pass.
Here's a sample of the text:
br><br>13/03/2015 10:00 (Stone, Fred B) : Lorem ipsum dolor sit
amet - Lorem ipsum dolor sit amet,. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. In velit massa, porta et arcu hendrerit,
pellentesque pellentesque orci. Etiam ac ante pharetra, elementum nunc in,
gravida lacus. Quisque sollicitudin, tellus at imperdiet condimentum, orci ante
accumsan elit, sit amet lacinia enim purus eu nisl. Phasellus ullamcorper
vestibulum tortor id fringilla.<br><br>2015-03-13T10:00:13 (Stone, Fred
B) : Quisque ipsum risus, cursus at purus in, dignissim molestie risus.
Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae
consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet
et ipsum nec, cursus volutpat leo.<br><br>13/03/2015 09:58 (Stone, Fred B)
: <br> Quisque ipsum risus, cursus at purus in, dignissim molestie risus.
Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae
consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet
et ipsum nec, cursus volutpat leo<br> Quisque ipsum risus, cursus at purus in,
dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a
augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis
nisl justo, imperdiet et ipsum nec, cursus volutpat leo<br><br>11/03/2015
11:12 (Smith, Mark L) : Assigned to: Stone, Fred B L<br>Quisque
ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor
odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat.
Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus
volutpat leo<br><br>11/03/2015 11:09 (Johnson, Rod R) : <br> Quisque
ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor
odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat.
Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus
volutpat leo<br><br>19/02/2015 15:30 (Smith, Mark L) : Assigned to:
Stone, Fred B LQuisque ipsum risus, cursus at purus in, dignissim molestie
risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan,
vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo,
imperdiet et ipsum nec, cursus volutpat leo
Resulting matches (italicized) should look like:
13/03/2015 10:00 (Stone, Fred B) : Lorem ipsum dolor sit
amet - Lorem ipsum dolor sit amet,. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. In velit massa, porta et arcu hendrerit,
pellentesque pellentesque orci. Etiam ac ante pharetra, elementum nunc in,
gravida lacus. Quisque sollicitudin, tellus at imperdiet condimentum, orci ante
accumsan elit, sit amet lacinia enim purus eu nisl. Phasellus ullamcorper
vestibulum tortor id fringilla.
2015-03-13T10:00:13 (Stone, Fred B) : Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo.
etc.
Even returning each note (including the timestamp and UID) in a match would be acceptable. e.g.
13/03/2015 10:00 (Stone, Fred B) : Lorem ipsum dolor sit
amet - Lorem ipsum dolor sit amet,. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. In velit massa, porta et arcu hendrerit,
pellentesque pellentesque orci. Etiam ac ante pharetra, elementum nunc in,
gravida lacus. Quisque sollicitudin, tellus at imperdiet condimentum, orci ante
accumsan elit, sit amet lacinia enim purus eu nisl. Phasellus ullamcorper
vestibulum tortor id fringilla.
i hope this can help you (I'm not sure i did understand you):
/\d{2,4}[\/-]{1}\d{1,2}[\/-]{1}\d{2,4}[:0-9T&#;\s]*?\([\w']+?, [\w']+?[ \w]{0,2}\)/g
http://regexr.com/3fjvl
You can make the regex more specific if you want so.
Your input string maybe something like this: (first < was missed in your sample)
var mytext = "<br><br>13/03/2015 10:00 (Stone, Fred B) : Lorem ipsum dolor sit amet - Lorem ipsum dolor sit amet,. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In velit massa, porta et arcu hendrerit, pellentesque pellentesque orci. Etiam ac ante pharetra, elementum nunc in, gravida lacus. Quisque sollicitudin, tellus at imperdiet condimentum, orci ante accumsan elit, sit amet lacinia enim purus eu nisl. Phasellus ullamcorper vestibulum tortor id fringilla.<br><br>2015-03-13T10:00:13 (Stone, Fred B) : Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo.<br><br>13/03/2015 09:58 (Stone, Fred B) : <br> Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo<br> Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo<br><br>11/03/2015 11:12 (Smith, Mark L) : Assigned to: Stone, Fred B L<br>Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo<br><br>11/03/2015 11:09 (Johnson, Rod R) : <br> Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo<br><br>19/02/2015 15:30 (Smith, Mark L) : Assigned to: Stone, Fred B LQuisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo" ;
//Define Regex patterns:
var dataReg = new RegExp(/(?:^|<br><br>)(\d{2}\/\d{2}\/\d{4}) (\d{2}):(\d{2})\s*?\((\w+,[\w\s]+?)\)\s*:\s*([^]+?)(?=<br><br>\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}|$)/g) ;
//Extract Notes and Data:
var myData = [] ;
while ((myData = dataReg.exec(mytext)) !== null) {
console.log(myData);
}
Description of Regex Pattern: (regex Demo)
/: regex pattern starts
(?:^|<br><br>): start search from beginning or new <br><br> that comes date and time after it.
(\d{2}\/\d{2}\/\d{4}) (\d{2}):(\d{2}): extract date,hour and minute separated.
\s*?: pass spaces
\((\w+,[\w\s]+?)\): extract username inside the parenthesis (..)
\s*:\s*: pass the :
([^]+?): capture all user notes
(?=<br><br>\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}|$): stop capturing when next note or end of string is reached
/g: Global flag means do not return after first successful result
Note:
[0] is all matched string
[1] is date , [2] is hour, [3] is minutes, [4] is username
[5] is user's note
I have a string like this
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
<img src="foo.php?n=bar.jpg">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
<img src="somesource.jpg">
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
<img src="foo.php?n=bar_2.jpg">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
<img src="foo.php?n=bar_93.jpg">
.
I am now looking for a regex that gives me back all the <img> tags where the source contains bar
So the output should be:
<img src="foo.php?n=bar.jpg">
<img src="foo.php?n=bar_2.jpg">
<img src="foo.php?n=bar_93.jpg">
Could anyone help me out please ?
This regex should do it
<img((bar)|[^>])*?>(?(2)(?=)|(?!))
It uses a conditional expression to see if "bar" was matched in group 2
I got a small problem in one of my scripts.
I have a connection to a websocket and the messages are sent by server to my client.
The format is json. I wrote a simple interpreter which is searching for the quotes.
The function header:
ProcessEvent( string msg )
The function starts like this:
size_t hasType = msg.find("type");
size_t length = msg.size();
/* type */
string date, name, message, color, room, roomname;
int pos = msg.find("type");
if(pos!=std::string::npos) {
msg = msg.substr(pos+7);
int pos2 = msg.find_first_of("\"");
string type = msg.substr(0, pos2);
msg = msg.substr(pos2);
The basic problem is on that part:
/* message */
pos = msg.find("message");
if(pos!=std::string::npos) {
msg = msg.substr(pos+10);
pos2 = msg.find_first_of("\"");
cout << msg << endl;
CONSOLE_Print("size: "+UTIL_ToString(msg.size())+", pos2: "+UTIL_ToString(pos2));
message = msg.substr(0, pos2);
msg = msg.substr(pos2);
} else { message = "empty"; }
As you can see i tried already to debug into this problem.
The problem only occurs on messages with a huge length (this is the only thing coming up from data).
The return of the second debug is this:
size: 949, pos2: -1
The problem is now, that the example input into the client is this:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit
amet.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse
molestie consequat, vel illum dolore eu feugiat nulla facilisis at
vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat.
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem
vel eum iriure dolor in hendrerit in vulputate velit esse molestie
consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et
accumsan et iusto odio dignissim qui blandit praesent luptatum zzril
delenit augue duis dolore te feugait nulla facilisi.
Nam liber tempor cum soluta nobis eleifend option congue nihil
imperdiet doming id quod mazim placerat facer
This are 300 chars Lorem Ipsum. The text if the debug print isn't 300 chars anymore:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit
amet. Duis autem vel eum iriure dolor in hendrerit in vulputate
That is also obviously the reason why it couldnt find my trailing quote for this message. On the first text there isnt a trailing quote also, i just used to copy the text from my input, this isnt the normal format. The main problem is not the missing quote, its that the string is stripped without a reason.
The whole exception is this:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr
Aborted
What is the reason that the string is cut like this?
So I'm trying to get my routing to work so that I have permalinks in my url for sharing. I.E. "/getting-started".
I can't seem to figure out how the model/serialize works, so how does ember-data know how to find my object with a string? I already did an attempt at the queryFixtures and it returns the right model but it isn't set
Here is my code:
Router:
App.Router.map (match) ->
#resource 'topics', {path: "/support"}, ->
#route 'topic', {path: '/:permalink'}
# Support Routes
App.TopicsRoute = Ember.Route.extend
model: ->
this.store.find('topic')
App.TopicsTopicRoute = Ember.Route.extend
# serialize: (model, params) ->
# return { topic_id: model.get(params.topic_id) }
model: (param) ->
#get('store').findQuery App.Topic, {permalink: param.permalink}
setupController: (controller, model) ->
controller.set("content", model)
actions:
error: (error) ->
console.log error
App.ApplicationAdapter = DS.FixtureAdapter.extend
queryFixtures: (fixtures, query, type) ->
fixtures.filter (item) ->
for property, value of query
if item[property] == value
return item
else
false
And my fixtures:
App.Topic = DS.Model.extend
name: DS.attr('string')
permalink: DS.attr('string')
position: DS.attr('number')
# Fiture data
App.Topic.FIXTURES = [
{
id: 1
name: "Getting Started"
permalink: "getting-started"
position: 1
articles: [
{ name: "test 1", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." },
{ name: "test 2", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." },
{ name: "test 3", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." }
]
},
{
id: 2
name: "Frequently Asked Questions"
permalink: "frequently-asked-questions"
position: 2
articles: [
{ name: "test 1", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." },
{ name: "test 2", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." }
]
},
{
id: 3
name: "Tips & Tricks"
permalink: "tips-tricks"
position: 3
articles: [
{ name: "test 1", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." }
]
}
]
For this answer I will assume you're using the version 1.0.0 of Ember and the Beta version 1.0.0 of Ember Data.
For the router you described, you should setup the following Route objects:
App.TopicsIndexRoute = Ember.Route.extend
and
App.TopicIndexRoute = Ember.Route.extend
otherwise Ember will have issues passing the correct model to the routes.
Now in the TopicIndexRoute (TopicsTopicRoute in your code) you use the model hook, which is called ONLY when entering the URL or reloading the page and NOT when coming to the route through the {{link-to}} helper (http://emberjs.com/api/classes/Ember.Route.html#method_model).
When you're going to the TopicIndexRoute from a {{link-to}} helper, the "ember magic" match the dynamic segment (http://emberjs.com/guides/routing/specifying-a-routes-model/#toc_dynamic-models) to the corresponding model only if it's the model's ID. I don't know how to solve this yet. This might help: Using a non-ID dynamic parameter with the ember router v2
I don't know if the fixtures you're using are working but when setting relationships you should use (at least that's how it's shown in the guides: http://emberjs.com/guides/models/connecting-to-an-http-server/#toc_json-conventions) the model ID instead of declaring the instance. It would look like this:
App.Article.FIXTURES = [
{
id: 1,
name: "test 1",
content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et."
},
{
id: 2,
name: "test 2",
content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et."
},
{
id: 3,
name: "test 3",
content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et."
}
]
App.Topic.FIXTURES = [
{
id: 1
name: "Getting Started"
permalink: "getting-started"
position: 1
articles: [1,2,3]
}
]
I hope this helps you.
I have a model ..
class News(models.Model):
date = models.DateField(auto_now=True)
title = models.CharField(max_length=100)
slug = models.CharField(max_length=100)
text = models.TextField()
def __unicode__(self):
return self.title
def get_absolute_url(self):
return ('view_item', None, {'slug': self.slug})
class Meta:
verbose_name_plural = "News"
and the template file is as follows
{% extends 'base.html' %}
{% block title %}Welcome to my blog{% endblock %}
{% block content %}
{% if news %}
{% for singleitem in news %}
<h2>{{ singleitem.title }}</h2>
<p>{{ singleitem.date }}</p>
{{ singleitem.text }}
{% endfor %}
{% endif %}
{% endblock %}
the input in the textbox is as follows
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam pharetra aliquet arcu. Praesent non elit dolor, vel bibendum lectus. Proin mauris nisl, faucibus sit amet commodo et, interdum a ligula. Ut sapien leo, egestas non molestie vitae, aliquam eget purus. Sed at libero sapien. Ut id dolor elit. Ut placerat massa massa. Quisque posuere pellentesque lorem ac tristique. Nam lacinia tincidunt felis ac adipiscing. Suspendisse elit risus, cursus vel dignissim et, lacinia sit amet neque. Morbi tincidunt sem id augue fermentum adipiscing.
</p>
<p>
Quisque commodo lorem eu tortor auctor sodales. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent condimentum ante id erat dapibus ac rhoncus dui hendrerit. Curabitur at diam vitae ipsum sagittis vestibulum ac et metus. Donec in molestie justo. In eget fringilla lacus. Vestibulum gravida quam quis dui aliquam ut gravida justo rhoncus. Nam euismod mattis purus pulvinar scelerisque. Nam tortor augue, cursus vel ultrices ut, pharetra id leo. Etiam tristique, augue aliquam faucibus dictum, libero justo egestas ante, ut volutpat metus nunc vitae arcu. Aliquam erat volutpat. Sed laoreet posuere sodales.
</p>
<p>
Donec urna urna, facilisis cursus auctor quis, eleifend nec diam. Proin eros dolor, aliquet ut euismod a, viverra sit amet turpis. Suspendisse at dolor quam. Phasellus suscipit rhoncus nisl at feugiat. Aenean in adipiscing purus. Etiam non ligula ligula. Nulla sit amet urna libero, et suscipit nulla. Suspendisse congue purus a eros accumsan eu volutpat ante euismod. Proin ut massa turpis, in gravida diam. Maecenas metus dui, cursus sed commodo eget, accumsan nec arcu.
</p>
which is displayed as follows, django doesn't recognize html tags
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Etiam pharetra aliquet arcu. Praesent non elit dolor, vel bibendum
lectus. Proin mauris nisl, faucibus sit amet commodo et, interdum a
ligula. Ut sapien leo, egestas non molestie vitae, aliquam eget purus.
Sed at libero sapien. Ut id dolor elit. Ut placerat massa massa.
Quisque posuere pellentesque lorem ac tristique. Nam lacinia tincidunt
felis ac adipiscing. Suspendisse elit risus, cursus vel dignissim et,
lacinia sit amet neque. Morbi tincidunt sem id augue fermentum
adipiscing. </p>
<p> Quisque commodo lorem eu tortor auctor sodales. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Praesent condimentum ante
id erat dapibus ac rhoncus dui hendrerit. Curabitur at diam vitae
ipsum sagittis vestibulum ac et metus. Donec in molestie justo. In
eget fringilla lacus. Vestibulum gravida quam quis dui aliquam ut
gravida justo rhoncus. Nam euismod mattis purus pulvinar scelerisque.
Nam tortor augue, cursus vel ultrices ut, pharetra id leo. Etiam
tristique, augue aliquam faucibus dictum, libero justo egestas ante,
ut volutpat metus nunc vitae arcu. Aliquam erat volutpat. Sed laoreet
posuere sodales. </p>
<p> Donec urna urna, facilisis cursus auctor quis, eleifend nec
diam. Proin eros dolor, aliquet ut euismod a, viverra sit amet turpis.
Suspendisse at dolor quam. Phasellus suscipit rhoncus nisl at feugiat.
Aenean in adipiscing purus. Etiam non ligula ligula. Nulla sit amet
urna libero, et suscipit nulla. Suspendisse congue purus a eros
accumsan eu volutpat ante euismod. Proin ut massa turpis, in gravida
diam. Maecenas metus dui, cursus sed commodo eget, accumsan nec arcu.
</p>
how to format text for output using django output field?
//yousuf
Use the "safe" filter. Like {{ singleitem.text|safe }}. I think thats what you are looking for.