Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby-URL到Markdown_Ruby_Markdown - Fatal编程技术网

Ruby-URL到Markdown

Ruby-URL到Markdown,ruby,markdown,Ruby,Markdown,这里完全是新手 我正在定制Brett Terpstra制作的脚本- 我的是一个不同的用途:我想用一个特定的标签将我的钉板书签保存到Markdown中dropbox中的一个文件中 我向其提供一个文本文件,如: Title: Yesterday is over. URL: http://www.jonacuff.com/blog/want-to-change-the-world-get-doing/ Tags: 2md, 2wcx, 2pdf Date: June 20, 2013 at 06:20

这里完全是新手

我正在定制Brett Terpstra制作的脚本-

我的是一个不同的用途:我想用一个特定的标签将我的钉板书签保存到Markdown中dropbox中的一个文件中

我向其提供一个文本文件,如:

Title: Yesterday is over.
URL: http://www.jonacuff.com/blog/want-to-change-the-world-get-doing/
Tags: 2md, 2wcx, 2pdf
Date: June 20, 2013 at 06:20PM
Image: notused
Excerpt: You can't start the next chapter of your life if you keep re-reading the last one. 
并输出降价文件

除了上面看到的“摘录”不止一行之外,一切都很好。有时是几段。当这种情况发生时,它就会停止工作。当我从命令行按enter键时,它仍在等待更多的输入

下面是一个无法处理的文件示例:

Title: Talking ’bout my Generation.
URL: http://blog.greglaurie.com/?p=8881
Tags: 2md, 2wcx, 2pdf
Date: June 28, 2013 at 09:46PM
Image: notused
Excerpt: Contrast two men from the 19th century: Max Jukes and Jonathan Edwards.

Max Jukes lived in New York. He did not believe in Christ or in raising his children in the way of the Lord. He refused to take his children to church, even when they asked to go. Of his 1,026 descendants:
•300 were sent to prison for an average term of 13 years
•190 were prostitutes
•680 were admitted alcoholics
His family, thus far, has cost the state in excess of $420,000 and has made no contribution to society.

Jonathan Edwards also lived in New York, at the same time as Jukes. He was known to have studied 13 hours a day and, in spite of his busy schedule of writing, teaching, and pastoring, he made it a habit to come home and spend an hour each day with his children. He also saw to it that his children were in church every Sunday. Of his 929 descendants:
•430 were ministers
•86 became university professors
•13 became university presidents
•75 authored good books
•7 were elected to the United States Congress
•1 was Vice President of the United States
Edwards’ family never cost the state one cent.

We tend to think that our decisions only affect ourselves, but they have ramifications for generations to come. 
下面是我运行命令后的屏幕截图: 我希望这是件容易的事。有什么想法吗


这个怎么样?修改您的输入。相应地,每行区域:

headers = {}
key = nil
input.each_line do |line|
  match = /^(?<key>\w+)\s*:\s*(?<value>.*)/.match(line)
  value = line
  if match
    key = match[:key].strip
    headers[key] = match[:value].strip
  else
    headers[key] += line
  end
end

首先,在just上分裂是危险的,因为这可能是内容。相反,简化的from代码regex/^\w+:.*/将与Word:Content匹配。因为摘录:后面的行没有前缀,所以需要保留最后一次看到的键,如果此行没有键,只需追加。您可能需要在其中添加一个换行符,这取决于您对标题信息所做的操作,但它似乎有效。

您是否有一个示例输入文件将其打断?我添加了一个额外的摘录:line,它就完成了。按照您的编码方式,它将前面的摘录吹走:行,但它不会挂起。感谢您的回复!我刚刚添加了一个示例文件和一个屏幕截图,显示了我试图运行它时的样子。我想问题不在于摘录的长度。问题在于摘录中的冒号。试着用单引号括住你的文字,一切都会好起来的。酷,我会试试的。我应该在输入文件或ruby脚本中,或者在哪里用单引号括住摘录吗?是的!!!真管用!虽然我遇到了不同的错误。不确定是否有关联。如果“标题”字段有斜线,例如:标题:本周末在Harvest/Riverside和Orange County。它又像这样出错了:截图-再次感谢你的帮助,我还有很多东西要学您需要更改头文件['Title'].gsub/[!*?'|]/,+.txt,才能删除/character.headers['Title'].gsub/[!*?'|\/\\\]/,+.txt-效果非常好!再次感谢你,尼克!
headers = {}
key = nil
input.each_line do |line|
  match = /^(?<key>\w+)\s*:\s*(?<value>.*)/.match(line)
  value = line
  if match
    key = match[:key].strip
    headers[key] = match[:value].strip
  else
    headers[key] += line
  end
end